Compare commits

..

No commits in common. "9b0d719c15f8085a5cf36f9724521367b9b118c3" and "779ef8b3279069c261ec426ce02ed0266c4b7c3d" have entirely different histories.

2 changed files with 0 additions and 120 deletions

View File

@ -1,60 +0,0 @@
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
using ll = int64_t;
const ll maxn = 10'0000 + 5, inf = 1e9 + 7;
struct C {
ll d, c, a;
inline bool operator<(const C &o) const {
return d < o.d;
}
} c[maxn];
ll n, g, ans;
std::map<ll, ll> cow_num, num_cowcount;
int main() {
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> g;
for (ll i = 1; i <= n; i++) {
std::cin >> c[i].d >> c[i].c >> c[i].a;
}
std::sort(c + 1, c + 1 + n);
num_cowcount[0] = inf;
for (ll i = 1; i <= n; i++) {
ll max_num_before = num_cowcount.rbegin()->first;
bool just_one_was_max = num_cowcount.rbegin()->second==1;
ll old_cownum = cow_num[c[i].c];
bool was_top = (old_cownum == max_num_before);
num_cowcount[old_cownum]--;
if (num_cowcount[old_cownum] == 0) {
num_cowcount.erase(old_cownum);
}
ll new_cownum = old_cownum + c[i].a;
cow_num[c[i].c] = new_cownum;
num_cowcount[new_cownum]++;
ll max_num_after = num_cowcount.rbegin()->first;
bool is_top = (new_cownum == max_num_after);
if ((max_num_before != max_num_after && !just_one_was_max) || (was_top != is_top)) {
ans++;
}
}
std::cout << ans << "\n";
}

View File

@ -1,60 +0,0 @@
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <istream>
#include <set>
#include <utility>
#include <vector>
using ll = int64_t;
std::vector<std::set<ll>> gotopos;
std::vector<ll> endpos;
ll n,k;
std::vector<ll> poscow,nposcow;
std::vector<ll> bcj;
std::vector<std::set<ll>> ans;
static inline ll find(ll idx){
if(idx==bcj[idx])return idx;
return bcj[idx]=find(bcj[idx]);
}
static inline void merge(ll a,ll b){
bcj[find(a)]=find(b);
}
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin>>n>>k;
poscow.resize(n+1);
gotopos.resize(n+1);
endpos.resize(n+1);
bcj.resize(n+1);
for(ll i=1;i<=n;i++)bcj[i]=i;
ans.resize(n+1);
for(ll i=1;i<=n;i++)poscow[i]=i;
for(ll i=1;i<=k;i++){
ll a,b;
std::cin>>a>>b;
gotopos[poscow[a]].emplace(b);
gotopos[poscow[b]].emplace(a);
std::swap(poscow[a],poscow[b]);
}
for(ll i=1;i<=n;i++){
endpos[poscow[i]]=i;
}
for(ll i=1;i<=n;i++)poscow[i]=i;
for(ll i=1;i<=n;i++){
merge(i, endpos[i]);
if(gotopos[i].size())gotopos[i].erase(gotopos[i].find(endpos[i]));
}
for(ll i=1;i<=n;i++){
ans[find(i)].emplace(i);
ans[find(i)].insert(gotopos[i].cbegin(),gotopos[i].cend());
}
for(ll i=1;i<=n;i++){
std::cout<<ans[find(i)].size()<<"\n";
}
}