Submission #440412

# Submission time Handle Problem Language Result Execution time Memory
440412 2021-07-02T08:53:13 Z i_am_noob Distributing Candies (IOI21_candies) C++17
0 / 100
513 ms 10428 KB
#include "candies.h"
#include<bits/stdc++.h>
using namespace std;

#define ll long long
//#define int ll
#define rep(n) rep1(i,n)
#define rep1(i,n) rep2(i,0,n)
#define rep2(i,a,b) for(int i=a; i<(b); ++i)
#define rep3(i,a,b) for(int i=a; i>=(b); --i)
#define chkmax(a,b) (a=max(a,b))
#define chkmin(a,b) (a=min(a,b))
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define pb push_back
#define pii pair<int,int>
#define pow2(x) (1ll<<(x))
#ifdef zisk
#define bug(...) cerr << "#" << __LINE__ << ": " << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T x){cerr << x << endl;}
template<typename T, typename ...S> void _do(T x, S... y){cerr << x << ", "; _do(y...);}
#else
#define bug(...) 49
#endif

const int maxn=200005,K=490;
int n,q,op[maxn/K+5],valb[maxn/K+5],vals[maxn];
int pos[maxn],cc[maxn];

vector<int> distribute_candies(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    n=sz(c);
    q=sz(l);
    vector<int> res(n);
    {
    int tmp[maxn];
    rep(n) tmp[i]=i;
    sort(tmp,tmp+n,[&c](int i, int j){return c[i]<c[j];});
    rep(n) pos[tmp[i]]=i;
    rep(n) cc[i]=c[tmp[i]];
	}
    rep1(j,q){
    	bool flag=0;
		rep(n/K+1){
			if(!flag){
				int maxpos=min(n-1,i*K+K-1);
				int tmp=vals[maxpos];
				if(op[i]==1) tmp=cc[maxpos];
				if(op[i]==-1) tmp=0;
				tmp+=valb[i]+v[j];
				if(tmp>0&&tmp<cc[maxpos]){
					bug(j,i);
					for(int k=i*K; k<min(n,(i+1)*K); ++k){
						if(op[i]==1) vals[k]=cc[k];
						if(op[i]==-1) vals[k]=0;
						vals[k]+=valb[i]+v[j];
						chkmin(vals[k],cc[k]);
						chkmax(vals[k],0);
					}
					flag=1;
					op[i]=0,valb[i]=0;
					continue;
				}
			}
			
			if(flag) valb[i]+=v[j];
			else if(v[j]>0) op[i]=1,valb[i]=0;
			else op[i]=-1,valb[i]=0;
		}
		//rep(n/K+1) bug(op[i],valb[i]);
		//rep(n) bug(vals[i]);
    }
    rep(n){
    	if(op[i/K]==1) vals[i]=cc[i];
		if(op[i/K]==-1) vals[i]=0;
		vals[i]+=valb[i/K];
		chkmin(vals[i],cc[i]);
		chkmax(vals[i],0);
		res[pos[i]]=vals[i];
    }
    return res;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:23:18: warning: statement has no effect [-Wunused-value]
   23 | #define bug(...) 49
      |                  ^~
candies.cpp:52:6: note: in expansion of macro 'bug'
   52 |      bug(j,i);
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Incorrect 1 ms 1100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 513 ms 10428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Incorrect 1 ms 1100 KB Output isn't correct
3 Halted 0 ms 0 KB -