Submission #990118

#TimeUsernameProblemLanguageResultExecution timeMemory
990118VinhLuuTeams (IOI15_teams)C++17
0 / 100
4091 ms165712 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #define ll long long #define fi first #define se second #define pb push_back #define all(lmao) lmao.begin(), lmao.end() using namespace std; typedef pair<int,int> pii; typedef tuple<int,int,int> tp; const int N = 5e5 + 5; int block = 555; const int mod = 1e9 + 7; //const ll oo = 5e18; int n, cnt, R[N], m; struct NODE{ int l, r, w; } st[N * 25]; int Newchild(int val){ cnt++; st[cnt].w = val; st[cnt].l = st[cnt].r = 0; return cnt; } int Newnode(int l,int r){ cnt++; st[cnt].l = l, st[cnt].r = r; st[cnt].w = st[l].w + st[r].w; return cnt; } int build(int l,int r){ if(l == r) return Newchild(0); int mid = (l + r) / 2; return Newnode(build(l, mid), build(mid + 1, r)); } int update(int i,int l,int r,int u){ if(l > u || r < u) return i; if(l == r) return Newchild(st[i].w + 1); int mid = (l + r) / 2; return Newnode(update(st[i].l, l, mid, u), update(st[i].r, mid + 1, r, u)); } int get(int i,int l,int r,int u,int v){ if(l > r || l > v || r < u) return 0; if(u <= l && r <= v) return st[i].w; int mid = (l + r) / 2; return get(st[i].l, l, mid, u, v) + get(st[i].r, mid + 1, r, u, v); } vector<int> add[N]; void init(int _n, int A[], int B[]){ n = _n; m = 0; for(int i = 0; i < n; i ++) add[A[i]].pb(B[i]); R[0] = build(1, n); for(int i = 1; i <= n; i ++){ int cur = R[i - 1], tmp = 0; for(auto j : add[i]){ tmp = update(cur, 1, n, j); swap(tmp, cur); } R[i] = cur; } // for(int i = 1; i <= n; i ++){ // cerr << i << " h\n"; // for(int j = 1; j <= n; j ++){ // cerr << get(R[i], 1, n, 1, j) << " "; // } // cerr << "\n"; // } } int mark[N]; int can(int M,int k[]){ vector<int> K; for(int i = 0; i < M; i ++) K.pb(k[i]); sort(all(K)); vector<pii> sk; int sub = 0; for(int i = 0; i < M; i ++){ int l = 1, r = n, mid, ans = -1; while(l <= r){ mid = (l + r) / 2; int val = get(R[K[i]], 1, n, 1, mid); if(sk.empty() || sk.back().fi <= mid) val -= sub; else{ int le = 0, ri = sk.size() - 1, mi, u = -1; while(le <= ri){mi = (le + ri) / 2; if(sk[mi].fi >= mid) u = mi, l = mi + 1; else r = mi - 1;} int lef = (u == sk.size() - 1 ? 1 : sk[u + 1].fi + 1); val = val - (sub - mark[sk[u].se] + get(R[K[sk[u].se]], 1, n, lef, sk[u].fi)); } if(val >= K[i]){ ans = mid; r = mid - 1; }else l = mid + 1; } if(ans == -1) return 0; int tmp = 1; while(!sk.empty() && sk.back().fi <= ans){ sub = sub - get(R[K[sk.back().se]], 1, n, tmp, sk.back().fi); tmp = sk.back().fi + 1; sk.pop_back(); } if(!sk.empty()){ int lmao = get(R[K[sk.back().se]], 1, n, 1, ans); mark[sk.back().se] -= lmao; sub -= lmao; } mark[i] = get(R[K[i]], 1, n, 1, ans) + (sk.empty() ? 0 : mark[sk.back().se]); sub += get(R[K[i]], 1, n, 1, ans); sk.pb({ans, i}); } return 1; // int ptr = -1; // bool ff = true; // priority_queue<int,vector<int>, greater<int>> pq; // for(auto j : K){ // while(ptr + 1 < vr.size() && vr[ptr + 1].fi <= j) pq.push(vr[ptr + 1].se), ptr++; // int u = j; // while(u){ // if(pq.empty()) return 0; // if(pq.top() >= j) u--; // pq.pop(); // } // } // return 1; } //#define lpv #ifdef lpv int n_, a_[N], b_[N]; int inQ; int inM, inK[N]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n_ >> inQ; for (int i = 0; i < n_; ++i) cin >> a_[i] >> b_[i]; init(n_, a_, b_); while (inQ--) { cin >> inM; for (int i = 0; i < inM; ++i) cin >> inK[i]; cout << can(inM, inK) << "\n"; } } #endif // lpv

Compilation message (stderr)

teams.cpp: In function 'int can(int, int*)':
teams.cpp:101:40: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
  101 |             int le = 0, ri = sk.size() - 1, mi, u = -1;
      |                              ~~~~~~~~~~^~~
teams.cpp:105:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |             int lef = (u == sk.size() - 1 ? 1 : sk[u + 1].fi + 1);
      |                        ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...