Submission #446206

#TimeUsernameProblemLanguageResultExecution timeMemory
446206arnold518Distributing Candies (IOI21_candies)C++17
Compilation error
0 ms0 KiB
#include "candies.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e5; const ll INF = 1e18; struct Query { int l, r, v; }; int N, Q; int A[MAXN+10]; Query B[MAXN+10]; int ans[MAXN+10]; vector<int> distribute_candies(vector<int> _C, vector<int> _L, vector<int> _R, vector<int> _V) { N=_C.size(); Q=_L.size(); for(int i=1; i<=N; i++) A[i]=_C[i-1]; for(int i=1; i<=Q; i++) B[i]={_L[i-1]+1, _R[i-1]+1, _V[i-1]}; vector<ll> V; for(int i=1; i<=Q; i++) { if(B[i].v>0) { ll x=0, y=0; while(!V.empty()) { ll x2, y2; x2=V.back(); if(V.size()%2) // / { y2=x2-x+y; } else // -- { y2=y; } if(y2<x2-B[i].v) { V.push_back(y2+B[i].v); break; } else { V.pop_back(); } x=x2; y=y2; } if(V.empty()) { V.push_back(y+B[i].v); } } else { ll x=0, y=0; while(!V.empty()) { ll x2, y2; x2=V.back(); if(V.size()%2) // / { y2=x2-x+y; } else // -- { y2=y; } if(y2>-B[i].v) { V.push_back(x2-y2-B[i].v); break; } else { V.pop_back(); } x=x2; y=y2; } } /for(auto it : V) printf("%lld ", it); printf("\n"); } vector<pii> V2; for(int i=1; i<=N; i++) V2.push_back({A[i], i}); sort(V2.begin(), V2.end()); int pt=0; ll x=0, y=0; while(!V.empty()) { ll x2, y2; x2=V.back(); if(V.size()%2) // / { y2=x2-x+y; } else // -- { y2=y; } for(; pt<V2.size() && V2[pt].first<=x2; pt++) { if(V.size()%2) // / { ans[V2[pt].second]=y2-x2+V2[pt].first; } else // -- { ans[V2[pt].second]=y2; } } V.pop_back(); x=x2; y=y2; } for(; pt<V2.size(); pt++) { ans[V2[pt].second]=y; } return vector<int>(ans+1, ans+N+1); }

Compilation message (stderr)

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:89:9: error: expected primary-expression before '/' token
   89 |         /for(auto it : V) printf("%lld ", it); printf("\n");
      |         ^
candies.cpp:89:10: error: expected primary-expression before 'for'
   89 |         /for(auto it : V) printf("%lld ", it); printf("\n");
      |          ^~~
candies.cpp:111:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |         for(; pt<V2.size() && V2[pt].first<=x2; pt++)
      |               ~~^~~~~~~~~~
candies.cpp:126:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |     for(; pt<V2.size(); pt++)
      |           ~~^~~~~~~~~~