제출 #418810

#제출 시각아이디문제언어결과실행 시간메모리
418810peuch자리 배치 (IOI18_seats)C++17
5 / 100
4056 ms118296 KiB
#include "seats.h" #include<bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") const int MAXN = 1e6 + 10; const int MAXW = 1e3 + 10; vector<int> r, c; int h, w; vector<vector<int> > seg[2]; vector<pair<int, int> > seg2[2]; void update(int pos, int ini, int fim, int id, int val, int x, int k); int query(int pos, int ini, int fim, int p, int q, int x, int k); void update2(int pos, int ini, int fim, int id, int val, int k); pair<int, int> query2(int pos, int ini, int fim, int p, int q, int k); void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { r = R, c = C; h = H, w = W; seg[0] = vector<vector<int> > (h, vector<int> (4 * w)); seg[1] = vector<vector<int> > (w, vector<int> (4 * h)); seg2[0] = vector<pair<int, int> > (4 * h * w); seg2[1] = vector<pair<int, int> > (4 * h * w); for(int i = 0; i < r.size(); i++){ update(1, 0, w, c[i], i, r[i], 0); update(1, 0, h, r[i], i, c[i], 1); update2(1, 0, h * w - 1, i, r[i], 0); update2(1, 0, h * w - 1, i, c[i], 1); } } int cnt = 0; int swap_seats(int a, int b) { swap(r[a], r[b]); swap(c[a], c[b]); update2(1, 0, h * w - 1, a, r[a], 0); update2(1, 0, h * w - 1, a, c[a], 1); update2(1, 0, h * w - 1, b, r[b], 0); update2(1, 0, h * w - 1, b, c[b], 1); update(1, 0, w, c[a], a, r[a], 0); update(1, 0, h, r[a], a, c[a], 1); update(1, 0, w, c[b], b, r[b], 0); update(1, 0, h, r[b], b, c[b], 1); int cur = 1; int maxi = 0; int maxr = r[0], minr = r[0], maxc = c[0], minc = c[0]; int ret = 1; while(cur < h * w){ int r1, r2; int c1, c2; pair<int, int> rVal = query2(1, 0, h * w - 1, 0, cur, 0); pair<int, int> cVal = query2(1, 0, h * w - 1, 0, cur, 1); r1 = rVal.second; r2 = rVal.first; c1 = cVal.second; c2 = cVal.first; cnt++; // assert(c1 != minc || c2 != maxc || r1 != minr || r2 != maxr); // r1 = r2 = r[cur]; assert(r1 != -1 && r2 != h * w); while(maxr < r2){ maxr++; maxi = max(maxi, query(1, 0, w, minc, maxc, maxr, 0)); } while(minr > r1){ minr--; maxi = max(maxi, query(1, 0, w, minc, maxc, minr, 0)); } // c1 = c2 = c[cur]; while(maxc < c2){ maxc++; maxi = max(maxi, query(1, 0, h, minr, maxr, maxc, 1)); } while(minc > c1){ minc--; maxi = max(maxi, query(1, 0, h, minr, maxr, minc, 1)); } if(maxr == h - 1 && minr == 0 && maxc == w - 1 && minc == 0) break; cur = maxi; if(maxi == (maxr - minr + 1) * (maxc - minc + 1) - 1) ret++, cur++; } // fprintf(stderr, "%d\n", cnt); cnt = 0; ret++; return ret; } void update(int pos, int ini, int fim, int id, int val, int x, int k){ cnt++; if(ini > id || fim < id) return; if(ini == fim){ seg[k][x][pos] = val; return; } int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1; update(e, ini, mid, id, val, x, k); update(d, mid + 1, fim, id, val, x, k); seg[k][x][pos] = max(seg[k][x][e], seg[k][x][d]); } int query(int pos, int ini, int fim, int p, int q, int x, int k){ cnt++; if(ini > q || fim < p) return 0; if(ini >= p && fim <= q) return seg[k][x][pos]; int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1; return max(query(e, ini, mid, p, q, x, k), query(d, mid + 1, fim, p, q, x, k)); } void update2(int pos, int ini, int fim, int id, int val, int k){ cnt++; if(ini > id || fim < id) return; if(ini == fim){ seg2[k][pos] = make_pair(val, val); return; } int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1; update2(e, ini, mid, id, val, k); update2(d, mid + 1, fim, id, val, k); seg2[k][pos].first = max(seg2[k][e].first, seg2[k][d].first); seg2[k][pos].second = min(seg2[k][e].second, seg2[k][d].second); } pair<int, int> query2(int pos, int ini, int fim, int p, int q, int k){ cnt++; if(ini > q || fim < p) return make_pair(-1, h * w); if(ini >= p && fim <= q) return seg2[k][pos]; int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1; pair<int, int> eVal = query2(e, ini, mid, p, q, k); pair<int, int> dVal = query2(d, mid + 1, fim, p, q, k); pair<int, int> ret; ret.first = max(eVal.first, dVal.first); ret.second = min(eVal.second, dVal.second); return ret; }

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

seats.cpp: In function 'void give_initial_chart(int, int, std::vector<int>, std::vector<int>)':
seats.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int i = 0; i < r.size(); i++){
      |                 ~~^~~~~~~~~~
#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...