제출 #332824

#제출 시각아이디문제언어결과실행 시간메모리
332824cki86201팀들 (IOI15_teams)C++17
100 / 100
2072 ms153884 KiB
#include <bits/stdc++.h> #include "teams.h" using namespace std; #define Fi first #define Se second typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define all(x) (x).begin(), (x).end() #define pb push_back #define szz(x) (int)(x).size() #define rep(i, n) for(int i=0;i<(n);i++) typedef tuple<int, int, int> t3; int rt[500050], tn; int T[10000010], N; int ch[10000010][2]; vector <int> bl[500050]; int Ins(int prt, int l, int r, int x) { int me = ++tn; T[me] = T[prt] + 1; ch[me][0] = ch[prt][0]; ch[me][1] = ch[prt][1]; if(l != r) { int m = (l + r) >> 1; if(x <= m) ch[me][0] = Ins(ch[prt][0], l, m, x); else ch[me][1] = Ins(ch[prt][1], m+1, r, x); } return me; } int read(int prt, int l, int r, int s, int e) { if(s <= l && r <= e) return T[prt]; int m = (l + r) >> 1, res = 0; if(s <= m) res += read(ch[prt][0], l, m, s, e); if(m < e) res += read(ch[prt][1], m+1, r, s, e); return res; } int Read(int x, int l, int r) { return read(rt[x], 1, N, l, r); } void init(int N, int A[], int B[]) { ::N = N; rt[0] = ++tn; for(int i=0;i<N;i++) bl[A[i]].pb(B[i]); for(int i=1;i<=N;i++) { rt[i] = rt[i-1]; for(int r : bl[i]) { rt[i] = Ins(rt[i], 1, N, r); } } } int dp[200020]; int can(int M, int K[]) { sort(K, K+M, greater<>()); vector <pii> V; V.pb({N+1, 0}); for(int i=0, s=0;i<M;i++) { if(szz(V) && V.back().Fi == K[i]) V.back().Se += K[i]; else V.pb({K[i], K[i]}); s += K[i]; if(s > N) return 0; } vector <int> iv = {0}; vector <int> cv; auto mp = [&](int xi, int yi) { int xv = dp[xi], yv = dp[yi]; int low = 1, high = V[yi].Fi - 1, res = 0; while(low <= high) { int mid = (low + high) >> 1; if(Read(mid, V[yi].Fi, V[xi].Fi - 1) < yv - xv) res = mid, low = mid + 1; else high = mid - 1; } return res; }; for(int i=1;i<szz(V);i++) { auto [x, cnt] = V[i]; while(szz(cv) && cv.back() >= x) cv.pop_back(), iv.pop_back(); int j = iv.back(); dp[i] = dp[j] + Read(x, x, V[j].Fi - 1) - cnt; if(dp[i] < 0) return 0; while(szz(iv) && dp[i] < dp[iv.back()]) iv.pop_back(), cv.pop_back(); int p = mp(iv.back(), i); while(szz(cv) && cv.back() >= p) { iv.pop_back(); cv.pop_back(); p = mp(iv.back(), i); } iv.pb(i); cv.pb(p); } return 1; }

컴파일 시 표준 에러 (stderr) 메시지

teams.cpp: In function 'void init(int, int*, int*)':
teams.cpp:45:34: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   45 | void init(int N, int A[], int B[]) {
      |                                  ^
teams.cpp:17:18: note: shadowed declaration is here
   17 | int T[10000010], N;
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...