Submission #470393

#TimeUsernameProblemLanguageResultExecution timeMemory
470393wiwihoDistributing Candies (IOI21_candies)C++17
8 / 100
423 ms37648 KiB
#include "candies.h" #include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define ef(a) emplace_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define tomax(a, b) ((a) = max((a), (b))) #define tomin(a, b) ((a) = min((a), (b))) #define topos(a) ((a) = (((a) % MOD + MOD) % MOD)) #define uni(a) a.resize(unique(iter(a)) - a.begin()) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 2147483647; const ll LLMAX = 1LL << 60; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } ll ifloor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a < 0) return (a - b + 1) / b; else return a / b; } ll iceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a > 0) return (a + b - 1) / b; else return a / b; } struct Node{ ll mn = 0, mx = 0, tag = 0; }; vector<Node> st; void addtag(int id, ll v){ st[id].mn += v; st[id].mx += v; st[id].tag += v; } void push(int id){ addtag(2 * id + 1, st[id].tag); addtag(2 * id + 2, st[id].tag); st[id].tag = 0; } void modify(int l, int r, ll v, int L, int R, int id){ if(l == L && r == R){ addtag(id, v); return; } push(id); int M = (L + R) / 2; if(r <= M) modify(l, r, v, L, M, 2 * id + 1); else if(l > M) modify(l, r, v, M + 1, R, 2 * id + 2); else{ modify(l, M, v, L, M, 2 * id + 1); modify(M + 1, r, v, M + 1, R, 2 * id + 2); } st[id].mn = min(st[2 * id + 1].mn, st[2 * id + 2].mn); st[id].mx = max(st[2 * id + 1].mx, st[2 * id + 2].mx); } bool type; ll val; int query(ll c, int L, int R, int id, ll nmn = LLMAX, ll nmx = -LLMAX){ if(L == R){ nmn = min(nmn, st[id].mn); nmx = max(nmx, st[id].mx); // cerr << "query " << L << " " << R << " " << st[id].mn << " " << nmn << " " << nmx << "\n"; type = st[id].mn == nmn; val = type ? nmx : nmn; return L; } push(id); int M = (L + R) / 2; ll tmn = min(nmn, st[2 * id + 2].mn); ll tmx = max(nmx, st[2 * id + 2].mx); if(tmx - tmn >= c) return query(c, M + 1, R, 2 * id + 2, nmn, nmx); else return query(c, L, M, 2 * id + 1, tmn, tmx); } ll queryp(ll x, int L, int R, int id){ if(L == R) return st[id].mn; push(id); int M = (L + R) / 2; if(x <= M) return queryp(x, L, M, 2 * id + 1); else return queryp(x, M + 1, R, 2 * id + 2); } void print(int L, int R, int id){ if(L == R){ // cerr << st[id].mn << " "; return; } push(id); int M = (L + R) / 2; print(L, M, 2 * id + 1); print(M + 1, R, 2 * id + 2); } vector<int> distribute_candies(vector<int> C, vector<int> L, vector<int> R, vector<int> V){ int q = L.size(); int n = C.size(); st.resize(4 * (q + 1)); vector<pair<pii, ll>> qry; for(int i = 0; i < q; i++){ qry.eb(mp(mp(L[i], i + 1), V[i])); if(R[i] < n - 1) qry.eb(mp(mp(R[i] + 1, i + 1), -V[i])); } lsort(qry); vector<int> ans(n); int qp = 0; ll sum = 0; for(int i = 0; i < n; i++){ while(qp < qry.size() && qry[qp].F.F == i){ modify(qry[qp].F.S, q, qry[qp].S, 0, q, 0); sum += qry[qp].S; qp++; } ans[i] = min((ll)C[i], sum); // cerr << "test " << i << " " << st[0].mx << " " << st[0].mn << "\n"; // print(0, q, 0); // cerr << "\n"; // if(st[0].mx - st[0].mn < C[i]){ // type = false; // val = st[0].mn; // assert(val == 0); // } // else{ // int t = query(C[i], 0, q, 0); // assert(type && val == sum); //// cerr << t << "\n"; // } //// cerr << type << " " << val << " " << sum << "\n"; // // if(type) ans[i] = sum - (val - C[i]); // else ans[i] = sum - val; // // if(sum >= C[i]){ // assert(ans[i] == C[i]); // } // else{ // assert(ans[i] == sum); // } } return ans; }

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:157:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  157 |         while(qp < qry.size() && qry[qp].F.F == i){
      |               ~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...