Submission #128174

#TimeUsernameProblemLanguageResultExecution timeMemory
128174dndhkMinerals (JOI19_minerals)C++14
40 / 100
18 ms1912 KiB
#include "minerals.h" #include <bits/stdc++.h> #define pb push_back #define all(v) ((v).begin(), (v).end()) #define sortv(v) sort(all(v)) #define sz(v) ((int)(v).size()) #define uniqv(v) (v).erase(unique(all(v)), (v).end()) #define umax(a, b) (a)=max((a), (b)) #define umin(a, b) (a)=min((a), (b)) #define FOR(i,a,b) for(int i = (a); i <= (b); i++) #define rep(i,n) FOR(i,1,n) #define rep0(i,n) FOR(i,0,(int)(n)-1) #define FI first #define SE second #define INF 2000000000 #define INFLL 1000000000000000000LL using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAX_N = 43000; int idx[MAX_N*2+1]; vector<pii> ans; bool chk[MAX_N+1]; vector<int> vt1, vt2; void solve(int x, int y){ /*printf("%d %d\n", x, y); for(int i=x; i<=y; i++){ printf("%d ", idx[i]); if(i==(x+y)/2){ printf("\n"); } } printf("\n");*/ if(y==x+1){ ans.pb({idx[x], idx[y]}); if(chk[x]){ Query(idx[x]); Query(idx[y]); } return; } int l = (y-x+1)/2; int m = l/2; int i; if(chk[x]){ int prv; i = x+l-1; while(m>0){ prv = Query(idx[i]); i--; m--; } for(int j = y; j >= x+l; j--){ int now = Query(idx[j]); if(now==prv){ Query(idx[j]); vt1.push_back(idx[j]); }else{ vt2.push_back(idx[j]); } prv = now; } }else{ int prv; i = x; while(m>0){ prv = Query(idx[i]); chk[i] = true; m--; i++; } i--; for(int j=x+l; j<=y; j++){ int now = Query(idx[j]); if(now==prv){ vt1.push_back(idx[j]); }else{ Query(idx[j]); vt2.push_back(idx[j]); } } } int i3 = i; int i2 = i+l; i = x+l-1; while(i>i3){ chk[i2] = false; idx[i2] = idx[i]; i--; i2--; } i2 = i + l+1; i = i3+1; while(!vt1.empty()){ chk[i] = true; idx[i] = vt1.back(); vt1.pop_back(); i++; } while(!vt2.empty()){ chk[i2] = false; idx[i2] = vt2.back(); vt2.pop_back(); i2++; } solve(x, i3*2 - x + 1); solve(i3*2 - x + 2, y); } void Solve(int N) { int prv = 0; int i1 = 1, i2 = N+1; for(int i=1; i<=N*2; i++){ int now = Query(i); if(now==prv){ idx[i2++] = i; }else{ idx[i1++] = i; } prv = now; } for(int i=1; i<=N*2; i++) Query(i); solve(1, N*2); for(int i=0; i<ans.size(); i++){ Answer(ans[i].first, ans[i].second); } }

Compilation message (stderr)

minerals.cpp: In function 'void Solve(int)':
minerals.cpp:124:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<ans.size(); i++){
               ~^~~~~~~~~~~
minerals.cpp: In function 'void solve(int, int)':
minerals.cpp:81:4: warning: 'prv' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(now==prv){
    ^~
minerals.cpp:62:4: warning: 'prv' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(now==prv){
    ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...