제출 #277561

#제출 시각아이디문제언어결과실행 시간메모리
277561ASDF123자리 배치 (IOI18_seats)C++14
5 / 100
4082 ms128120 KiB
//#include <seats.h> #include <bits/stdc++.h> #define chkmax(a, b) a = max(a, (b)) #define chkmin(a, b) a = min(a, (b)) #define pii pair<int, int> #define fr first #define sc second using namespace std; const int INF = 0x3f3f3f3f; const int N = 1e6 + 5; int r[N], c[N]; int ourH, ourW; struct node { int mn, mx; node() { mn = INF; mx = -INF; } }; struct Tree { vector <node> tree; Tree() { tree.resize(1e6 * 4); } void upd(int pos, int val, int v = 1, int tl = 1, int tr = 1e6) { if (tl == tr) { tree[v].mn = tree[v].mx = val; return; } int mid = tl + tr >> 1; if (pos <= mid) { upd(pos, val, v + v, tl, mid); } else { upd(pos, val, v + v + 1, mid + 1, tr); } tree[v].mn = min(tree[v + v].mn, tree[v + v + 1].mn); tree[v].mx = max(tree[v + v].mx, tree[v + v + 1].mx); } pii merge(pii a, pii b) { return { min(a.fr, b.fr), max(a.sc, b.sc) }; } pii getpair(int l, int r, int v = 1, int tl = 1, int tr = 1e6) { if (l <= tl && tr <= r) { return { tree[v].mn, tree[v].mx }; } if (l > tr || tl > r) { return { INF, -INF }; } int mid = tl + tr >> 1; return merge(getpair(l, r, v + v, tl, mid), getpair(l, r, v + v + 1, mid + 1, tr)); } int get(int l, int r, int type, int v = 1, int tl = 1, int tr = 1e6) { if (l <= tl && tr <= r) { if (type == 1) { return tree[v].mn; } else { return tree[v].mx; } } if (l > tr || tl > r) { if (type == 1) { return INF; } else { return -INF; } } int mid = tl + tr >> 1; int lft = get(l, r, type, v + v, tl, mid); int rgt = get(l, r, type, v + v + 1, mid + 1, tr); if (type == 1) { return min(lft, rgt); } else { return max(lft, rgt); } } } rows, columns; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { for (int i = 0; i < H * W; i++) { r[i + 1] = R[i] + 1; c[i + 1] = C[i] + 1; } ourH = H; ourW = W; for (int i = 1; i <= H * W; i++) { rows.upd(i, r[i]); columns.upd(i, c[i]); } } int subtask3(int a, int b) { a++, b++; swap(r[a], r[b]); swap(c[a], c[b]); rows.upd(a, r[a]); columns.upd(a, c[a]); rows.upd(b, r[b]); columns.upd(b, c[b]); int ans = 1; node R, C; R.mn = R.mx = r[1]; C.mn = C.mx = c[1]; int pos = 2; while (pos <= ourH * ourW) { chkmin(R.mn, r[pos]); chkmax(R.mx, r[pos]); chkmin(C.mn, c[pos]); chkmax(C.mx, c[pos]); int l = pos, r = ourH * ourW + 1; while (r - l > 1) { int mid = l + r >> 1; bool ok = 1; ok &= (rows.getpair(1, mid) == make_pair(R.mn, R.mx)); ok &= (columns.getpair(1, mid) == make_pair(C.mn, C.mx)); if (ok) { l = mid; } else { r = mid; } } pii res1 = rows.getpair(1, l); pii res2 = columns.getpair(1, l); if ((res1.sc - res1.fr + 1) * (res2.sc - res2.fr + 1) == l) { // + instead * ans++; } /*cout << "! " << pos << " " << l << ": " << endl; cout << res1.sc << " - " << res1.fr << " + " << 1 << endl; cout << res2.sc << " - " << res2.fr << " + " << 1 << endl;*/ pos = l + 1; } return ans; } int swap_seats(int a, int b) { // answer after swap /*if (ourH * ourW <= 10000) { int ans = 0; a++, b++; swap(r[a], r[b]); swap(c[a], c[b]); node R, C; for (int i = 1; i <= ourH * ourW; i++) { chkmin(R.mn, r[i]); chkmax(R.mx, r[i]); chkmin(C.mn, c[i]); chkmax(C.mx, c[i]); if ((R.mx - R.mn + 1) * (C.mx - C.mn + 1) == i) { ans++; } } return ans; }*/ if (ourH <= 1000 && ourW <= 1000) { return subtask3(a, b); } assert(false); } //signed main() { // vector <int> vecC, vecR; // int h, w; // cin >> h >> w; // vecC.resize(h * w); // vecR.resize(h * w); // for (int i = 0; i < h * w; i++) { // cin >> vecR[i] >> vecC[i]; // } // // give_initial_chart(h, w, vecR, vecC); // int Q; // cin >> Q; // while (Q--) { // int a, b; // cin >> a >> b; // cout << swap_seats(a, b) << endl; // } //}

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

seats.cpp: In member function 'void Tree::upd(int, int, int, int, int)':
seats.cpp:33:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |     int mid = tl + tr >> 1;
      |               ~~~^~~~
seats.cpp: In member function 'std::pair<int, int> Tree::getpair(int, int, int, int, int)':
seats.cpp:53:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |     int mid = tl + tr >> 1;
      |               ~~~^~~~
seats.cpp: In member function 'int Tree::get(int, int, int, int, int, int)':
seats.cpp:73:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   73 |     int mid = tl + tr >> 1;
      |               ~~~^~~~
seats.cpp: In function 'int subtask3(int, int)':
seats.cpp:118:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  118 |       int mid = l + r >> 1;
      |                 ~~^~~
#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...