Submission #1116179

# Submission time Handle Problem Language Result Execution time Memory
1116179 2024-11-21T10:07:05 Z ezzzay Nile (IOI24_nile) C++17
0 / 100
35 ms 12992 KB
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
const int N=3e5+5;
int par[N];
int sbtr[N];
int H;
int  mxJmpEven[N],mxJmpOdd[N],mxEven[N],mxOdd[N];
int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}
void unite(int x, int y){
	int px=find(x),py=find(y);
	if(px==py)return;
	if(sbtr[py]>sbtr[px])swap(px,py);
	int b=px,a=py;
	if (sbtr[x]%2) {
        mxJmpEven[b] = max(mxJmpEven[b], mxJmpOdd[a]);
        mxJmpOdd[b] = max(mxJmpOdd[b], mxJmpEven[a]);
        mxEven[b] = max(mxEven[b], mxOdd[a]);
        mxOdd[b] = max(mxOdd[b], mxEven[a]);
    }
    else { 
        mxJmpEven[b] = max(mxJmpEven[b], mxJmpEven[a]);
        mxJmpOdd[b] = max(mxJmpOdd[b], mxJmpOdd[a]);
        mxEven[b] = max(mxEven[b], mxEven[a]);
        mxOdd[b] = max(mxOdd[b], mxOdd[a]);
    }
	
	sbtr[px]+=sbtr[py];
	par[py]=px;
}
std::vector<long long> calculate_costs(std::vector<int> W, std::vector<int> A,
                                       std::vector<int> B, std::vector<int> E) {
    H=0;                                   	
	for(auto p:A)H+=p;                   	
    int q = (int)E.size();
    int n = W.size();
    for(int i=0;i<n;i++){
		par[i]=i;
		sbtr[i]=1;
		mxEven[i]=A[i]-B[i];
	}
 
	
    vector<ll>ans(q);
    vector<pair<ll,ll> >v;
    vector<pair<ll, pair<int,int> > >vc;
    for(int i=0;i<n;i++){
    	v.pb({W[i],i});
	}
	sort(v.begin(),v.end());
	for(int i=1;i<n;i++){
		int x=abs(v[i].ff-v[i-1].ff);
		int a=v[i-1].ss,b=v[i].ss;
		vc.pb({x,{a,b}});
	}
	sort(vc.begin(),vc.end());
	int idx=0;
	vector<pair<int,int>>vec;
	for(int i=0;i<q;i++){
		vec.pb({E[i],i});
	}
	sort(vec.begin(),vec.end());
	
	for(int f=0;f<q;f++){
		ll d=vec[f].ff;
		int k=vec[f].ss;
		while(vc[idx].ff<=d and idx<vc.size()){
			int a=vc[idx].ss.ff,b=vc[idx].ss.ss;
			unite(a,b);
			idx++;
		}
		ans[k]=H;
	}
	return ans;
}

Compilation message

nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:73:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   while(vc[idx].ff<=d and idx<vc.size()){
      |                           ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 12992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 12992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 12992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4432 KB Output isn't correct
2 Halted 0 ms 0 KB -