Submission #237002

#TimeUsernameProblemLanguageResultExecution timeMemory
237002LittleFlowers__Candies (JOI18_candies)C++17
100 / 100
135 ms11556 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;}) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int l,int r){return l+rng()%(r-l+1);} #define fasty ios_base::sync_with_stdio(0),cin.tie(0); #define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a) #define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a) #define forv(a,b) for(auto&a:b) #define fi first #define se second #define pb push_back #define ii pair<int,int> #define mt make_tuple #define all(a) a.begin(),a.end() #define reset(f, x) memset(f, x, sizeof(f)) #define bit(x,i) ((x>>(i-1))&1) #define on(x,i) (x|(1ll<<(i-1))) #define off(x,i) (x&~(1<<(i-1))) #define gg exit(0); const int N=200010; int n,tot; int a[N],l[N],r[N],dd[N]; priority_queue<ii> q; main(){ #define task "TASK" //freopen(task".inp","r",stdin); //freopen(task".out","w",stdout); forinc(i,1,n=in) q.push({a[i]=in,i}), l[i]=i-1,r[i]=i+1; a[0]=a[n+1]=-1e16; forinc(ti,1,(n+1)/2){ while(dd[q.top().se]) q.pop(); int val,i; tie(val,i)=q.top(); q.pop(); tot+=val; cout<<tot<<"\n"; dd[l[i]]=dd[r[i]]=1; a[i]=a[l[i]]+a[r[i]]-a[i]; q.push({a[i],i}); l[i]=l[l[i]], r[l[i]]=i; r[i]=r[r[i]], l[r[i]]=i; } }

Compilation message (stderr)

candies.cpp:29:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...