제출 #583421

#제출 시각아이디문제언어결과실행 시간메모리
583421M_W마상시합 토너먼트 (IOI12_tournament)C++17
17 / 100
1097 ms9388 KiB
#include <bits/stdc++.h> #define ii pair<int, int> using namespace std; int a[100001], t[400004], lazy[400004], k[100001]; int t2[400004]; void build(int v, int tl, int tr){ if(tl == tr){ t[v] = 1; t2[v] = k[tl]; return; } int tm = (tl + tr) >> 1; build(v * 2, tl, tm); build(v * 2 + 1, tm + 1, tr); t[v] = t[v * 2] + t[v * 2 + 1]; t2[v] = max(t2[v * 2], t2[v * 2 + 1]); } void push(int v){ if(lazy[v] != 1) return; t[v * 2] = 0; lazy[v * 2] = lazy[v]; t[v * 2 + 1] = 0; lazy[v * 2 + 1] = lazy[v]; lazy[v] = 0; } void ins(int v, int tl, int tr, int l, int r, int val){ if(l > r) return; if(tl == l && tr == r){ t[v] = 0; lazy[v] = 1; return; } push(v); int tm = (tl + tr) >> 1; ins(v * 2, tl, tm, l, min(r, tm), val); ins(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val); t[v] = t[v * 2] + t[v * 2 + 1]; return; } int query(int v, int tl, int tr, int l, int r){ if(l > r) return 0; if(tl == l && tr == r) return t[v]; push(v); int tm = (tl + tr) >> 1; return query(v * 2, tl, tm, l, min(r, tm)) + query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r); } int query_max(int v, int tl, int tr, int l, int r){ if(l > r) return INT_MIN; if(tl == l && tr == r) return t2[v]; int tm = (tl + tr) >> 1; return max(query_max(v * 2, tl, tm, l, min(r, tm)), query_max(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)); } vector<ii> v1[100001]; vector<int> v2[100001]; int val[100001], fwt[100001]; int nS[100001], nE[100001]; int query_f(int v){ int ret = 0; v++; for(; v > 0; v -= (v & -v)) ret += fwt[v]; return ret; } void ins_f(int v, int a){ v++; for(; v <= 100000; v += (v & -v)){ fwt[v] += a; } } int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { for(int i = 0; i < N; i++) k[i] = K[i]; build(1, 0, N - 1); for(int i = 0; i < C; i++){ int l = 0, r = N - 1; while(l < r){ int mid = (l + r) >> 1; int q = query(1, 0, N - 1, 0, mid); if(q >= S[i] + 1) r = mid; else l = mid + 1; } int head = l, diff = E[i] - S[i] + 1; r = N - 1; while(l < r){ int mid = (l + r) >> 1; int q = query(1, 0, N - 1, head, mid); if(q >= diff) r = mid; else l = mid + 1; } int tail = l; l = 0; r = N - 1; while(l < r){ int mid = (l + r) >> 1; int q = query(1, 0, N - 1, 0, mid); if(q >= S[i]) r = mid; else l = mid + 1; } head = S[i] == 0 ? 0 : l + 1; v1[head].push_back({tail, i}); v2[tail + 1].push_back(head); ins(1, 0, N - 1, head, tail - 1, 0); val[i] = query_max(1, 0, N - 1, head, tail - 1); // printf(">> %d %d %d\n", head, tail - 1, val[i]); nS[i] = head; nE[i] = tail; } int ans = 0, pos = 0; priority_queue<ii, vector<ii>, greater<ii>> pq; for(int i = 0; i < N; i++){ /* while(!pq.empty() && pq.top().second < i){ pq.pop(); } for(auto x : v2[i]) ins_f(x, -1); for(auto x : v1[i]){ if(val[x.second] > R) pq.push({x.second, x.first}); ins_f(x.second, 1); } int new_ans; if(!pq.empty()) new_ans = max(ans, query_f(pq.top().first) - 1); else new_ans = max(ans, query_f(100000)); if(new_ans > ans){ ans = new_ans; pos = i; } */ vector<int> qq; int aa = 0, now = 0; for(int j = 0; j < N - 1; j++){ if(j == i){ qq.push_back(R); } qq.push_back(K[j]); } if(i == N - 1) qq.push_back(R); // for(auto x : qq) printf("%d ", x); // printf("\n"); for(int j = 0; j < C; j++){ // printf(">> %d %d %d\n", mx, st, ed); int mx = 0; for(int e = nS[j]; e <= nE[j]; e++) mx = max(mx, qq[e]); for(int e = nS[j]; e <= nE[j]; e++) if(qq[e] != mx) qq[e] = -1; // for(auto x : qq) printf("%d ", x); // printf("\n"); if(mx == R) now++; } if(now > ans){ ans = now; pos = i; } // printf("end == \n"); } // printf(">> %d\n", ans); return pos; }

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

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:144:7: warning: unused variable 'aa' [-Wunused-variable]
  144 |   int aa = 0, now = 0;
      |       ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...