제출 #382760

#제출 시각아이디문제언어결과실행 시간메모리
382760alishahali1382마상시합 토너먼트 (IOI12_tournament)C++14
100 / 100
63 ms3172 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O2,unroll-loops") //#pragma GCC optimize("no-stack-protector,fast-math") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<pii, int> piii; typedef pair<ll, ll> pll; #define debug(x) cerr<<#x<<'='<<(x)<<endl; #define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl; #define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl; #define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;} #define all(x) x.begin(), x.end() #define pb push_back #define kill(x) return cout<<x<<'\n', 0; const int inf=1000000010; const ll INF=1000000000000001000LL; const int mod=1000000007; const int MAXN=100010, LOG=20; int n, m, k, u, v, x, y, t, a, b, ans, out; int fen[MAXN], ps[MAXN], dp[MAXN], par[MAXN]; vector<pii> vec; vector<int> stk; void add(int pos, int val){ for (; pos<MAXN; pos+=pos&-pos) fen[pos]+=val; } int get(int pos){ int res=0; for (; pos; pos-=pos&-pos) res+=fen[pos]; return res; } int Find(int val){ int pos=0; for (int i=16; ~i; i--) if ((pos+(1<<i))<=n && fen[pos+(1<<i)]<=val){ pos+=(1<<i); val-=fen[pos]; } return pos+1; } bool isgood(int l, int r){ return ps[r-2]==ps[l-1]; } bool cmp(pii i, pii j){ if (i.second==j.second) return i.first>j.first; return i.second<j.second; } int GetBestPosition(int nn, int m, int T, int *A, int *L, int *R){ n=nn; for (int i=1; i<=n; i++) add(i, 1); for (int i=1; i<n; i++) ps[i]=ps[i-1]+(A[i-1]>T); for (int i=0; i<m; i++){ int l=Find(L[i]), r=Find(R[i]+1); // debug2(l, r) if (isgood(l, r)) vec.pb({l, r}); for (int j=L[i]+1; j<=R[i]; j++) add(Find(L[i]+1), -1); } if (vec.empty()){ // debug("shit") return 0; } sort(all(vec), cmp); for (int i=0; i<vec.size(); i++){ while (stk.size() && vec[i].first<=vec[stk.back()].first){ par[stk.back()]=i; stk.pop_back(); } stk.pb(i); par[i]=-1; } for (int i=vec.size()-1; ~i; i--){ if (par[i]!=-1) dp[i]=dp[par[i]]; dp[i]++; if (dp[i]>ans) ans=dp[i], out=inf; if (dp[i]==ans && vec[i].first<out) out=vec[i].first; } // debug2(ans, out) return out-1; }

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

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:68:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for (int i=0; i<vec.size(); i++){
      |                ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...