제출 #964401

#제출 시각아이디문제언어결과실행 시간메모리
964401BestCrazyNoob자리 배치 (IOI18_seats)C++17
25 / 100
4025 ms76660 KiB
#include "seats.h" #include <cassert> #include <tuple> using namespace std; struct Node { int mn, mx; Node(): mn(1e9), mx(0) {} Node(int a): mn(a), mx(a) {} Node(Node l, Node r) { mn = min(l.mn, r.mn); mx = max(l.mx, r.mx); } }; struct SegTree { int sz; vector<Node> tree; int ql, qr; SegTree() {} SegTree(vector<int> v) { sz = 1; while (sz < v.size()) sz *= 2; tree.resize(2*sz, Node()); for (int i = 0; i < v.size(); i++) tree[sz+i] = Node(v[i]); for (int i = v.size(); i < sz; i++) tree[sz+i] = Node(); for (int i = sz-1; i >= 1; i--) tree[i] = Node(tree[2*i], tree[2*i+1]); } void update(int i, int x) { i += sz; tree[i] = Node(x); while (i > 1) { i /= 2; tree[i] = Node(tree[2*i], tree[2*i+1]); } } Node __query(int ni, int nl, int nr) { if (qr <= nl || nr <= ql) return Node(); if (ql <= nl && nr <= qr) return tree[ni]; int nm = (nl+nr)/2; return Node(__query(2*ni, nl, nm), __query(2*ni+1, nm, nr)); } pair<int, int> query(int l, int r) { ql = l; qr = r; auto res = __query(1, 0, sz); return {res.mn, res.mx}; } }; vector<int> R, C; SegTree rSeg, cSeg; void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { assert(H <= 10'000); assert(W <= 10'000); ::R = R; ::C = C; rSeg = SegTree(R); cSeg = SegTree(C); } int swap_seats(int a, int b) { // update swap(R[a], R[b]); swap(C[a], C[b]); rSeg.update(a, R[a]); rSeg.update(b, R[b]); cSeg.update(a, C[a]); cSeg.update(b, C[b]); // query int i = 1, ans = 1; int mnR = R[0], mnC = C[0], mxR = R[0], mxC = C[0]; while (i < C.size()) { tie(mnR, mxR) = rSeg.query(0, i); tie(mnC, mxC) = cSeg.query(0, i); if ((mxR - mnR + 1) * (mxC - mnC + 1) == i) { ans++; i += min(mxR - mnR + 1, mxC - mnC + 1); } else { i = (mxR - mnR + 1) * (mxC - mnC + 1); } } return ans; }

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

seats.cpp: In constructor 'SegTree::SegTree(std::vector<int>)':
seats.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         while (sz < v.size()) sz *= 2;
      |                ~~~^~~~~~~~~~
seats.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int i = 0; i < v.size(); i++) tree[sz+i] = Node(v[i]);
      |                         ~~^~~~~~~~~~
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:75:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     while (i < C.size()) {
      |            ~~^~~~~~~~~~
#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...