제출 #110686

#제출 시각아이디문제언어결과실행 시간메모리
110686wilwxk마상시합 토너먼트 (IOI12_tournament)C++11
100 / 100
159 ms8440 KiB
#include <bits/stdc++.h> using namespace std; struct node { int s, lz; }; const int MAXN=1e5+5; int qini[MAXN], qfim[MAXN]; pair<int, int> qv[MAXN]; multiset<int> s; node seg[MAXN*4]; int v[MAXN]; int n, m, cara, conta; int respf, maior; void refresh(int sind, int ini, int fim) { if(!seg[sind].lz) return; seg[sind].s=0; seg[sind].lz=0; if(ini==fim) return; int e=sind*2; int d=e+1; seg[e].lz=seg[d].lz=1; } void update(int sind, int ini, int fim, int qini, int qfim) { refresh(sind, ini, fim); if(qini>fim||qfim<ini) return; if(qini<=ini&&qfim>=fim) { seg[sind].lz=1; refresh(sind, ini, fim); return; } int m=(ini+fim)/2; int e=sind*2; int d=e+1; update(e, ini, m, qini, qfim); update(d, m+1, fim, qini, qfim); seg[sind].s=seg[e].s+seg[d].s; } int query(int sind, int ini, int fim, int val, int k) { refresh(sind, ini, fim); if(ini==fim) return seg[sind].s==val; int m=(ini+fim)/2; int e=sind*2; int d=e+1; refresh(e, ini, m); refresh(d, m+1, fim); if(k==1) { if(seg[e].s>=val) return query(e, ini, m, val, k); else return (m-ini+1)+query(d, m+1, fim, val-seg[e].s, k); } else { if(seg[e].s>val) return query(e, ini, m, val, k); else return (m-ini+1)+query(d, m+1, fim, val-seg[e].s, k); } } void build(int sind, int ini, int fim) { if(ini==fim) { seg[sind].s=1; return; } int m=(ini+fim)/2; int e=sind*2; int d=e+1; build(e, ini, m); build(d, m+1, fim); seg[sind].s=seg[e].s+seg[d].s; } int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) { n=N; m=C; cara=R; for(int i=1; i<=n; i++) v[i]=K[i-1]<cara; for(int i=1; i<=m; i++) qini[i]=S[i-1]+1, qfim[i]=E[i-1]+1; build(1, 1, n); for(int i=1; i<=m; i++) { int ini=query(1, 1, n, qini[i], 1); int fim=query(1, 1, n, qfim[i], 2); qini[i]=ini; qfim[i]=fim; qv[i]={ini, fim}; update(1, 1, n, ini+1, fim); } sort(qv+1, qv+1+m); qv[m+1].first=qv[m+1].second=1e9; int fim=0; int ind=0; while(v[fim+1]) fim++; fim++; for(int i=1; i<=n; i++) { if(i==fim+1) { fim=i-1; while(v[fim+1]) fim++; fim++; s.clear(); } //printf("sendo %d (fim=%d)...\n", i, fim); while(s.size()&&*s.begin()<i) s.erase(s.begin()); while(qv[ind+1].first<=i) { ind++; //printf(" add qv[%d] (%d %d)\n", ind, qv[ind].first, qv[ind].second); if(qv[ind].second>fim) continue; s.insert(qv[ind].second); } //printf(" %d > %d\n", i, s.size()); if(s.size()>maior) maior=s.size(), respf=i-1; } return respf; }

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

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:82:2: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
  while(v[fim+1]) fim++; fim++;
  ^~~~~
tournament.cpp:82:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
  while(v[fim+1]) fim++; fim++;
                         ^~~
tournament.cpp:86:4: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
    while(v[fim+1]) fim++; fim++;
    ^~~~~
tournament.cpp:86:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
    while(v[fim+1]) fim++; fim++;
                           ^~~
tournament.cpp:98:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(s.size()>maior) maior=s.size(), respf=i-1;
      ~~~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...