제출 #393239

#제출 시각아이디문제언어결과실행 시간메모리
393239maximath_1자리 배치 (IOI18_seats)C++11
70 / 100
4067 ms60808 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; #define mx(a, b) (a > b ? a : b) #define mn(a, b) (a < b ? a : b) #define ll long long const int inf = 2; const int MX = 1000005; const int dx[] = {1, 1, -1, -1}; const int dy[] = {1, -1, 1, -1}; struct segtree{ int mn[MX * 4], lz[MX * 4]; int cnt[MX * 4]; int sz; void init(int a){ sz = a; build(1, 0, sz - 1); } void build(int nd, int cl, int cr){ if(cl == cr) return void(cnt[nd] = 1); build(nd * 2, cl, (cl + cr) / 2); build(nd * 2 + 1, (cl + cr) / 2 + 1, cr); merge(nd, nd * 2, nd * 2 + 1); } void prop(int nd, int cl, int cr){ if(lz[nd]){ mn[nd] += lz[nd]; if(cl != cr){ lz[nd * 2] += lz[nd]; lz[nd * 2 + 1] += lz[nd]; } lz[nd] = 0; } } void merge(int m, int l, int r){ if(mn[l] < mn[r]){ mn[m] = mn[l]; cnt[m] = cnt[l]; }else if(mn[l] > mn[r]){ mn[m] = mn[r]; cnt[m] = cnt[r]; }else{ mn[m] = mn[l]; cnt[m] = cnt[l] + cnt[r]; } } void upd(int nd, int cl, int cr, int lf, int rg, int val){ prop(nd, cl, cr); if(lf > rg || rg < cl || cr < lf) return; if(lf <= cl && cr <= rg){ lz[nd] += val; prop(nd, cl, cr); return; } upd(nd * 2, cl, (cl + cr) / 2, lf, rg, val); upd(nd * 2 + 1, (cl + cr) / 2 + 1, cr, lf, rg, val); merge(nd, nd * 2, nd * 2 + 1); } void upd(int lf, int rg, int val){ if(lf > rg) return; upd(1, 0, sz - 1, lf, rg, val); } void dfs(int nd, int cl, int cr){ if(cl == cr){ cout << mn[nd] << " "; return; } dfs(nd * 2, cl, (cl + cr) / 2); dfs(nd * 2 + 1, (cl + cr) / 2 + 1, cr); } void print(){ dfs(1, 0, sz - 1); cout << endl; } } seg; int h, w, ans; vector<int> r, c; vector<vector<int> > mp; void give_initial_chart(int H, int W, vector<int> R, vector<int> C){ r = R; c = C; h = H; w = W; if(h > w){ swap(h, w); swap(r, c); } mp.assign(h + 2, vector<int>(w + 2, r.size())); for(int i = 0; i < r.size(); i ++){ r[i] ++; c[i] ++; mp[r[i]][c[i]] = i; } seg.init(r.size()); for(int i = 0; i <= h; i ++) for(int j = 0; j <= w; j ++){ vector<int> ord = {mp[i][j], mp[i + 1][j], mp[i][j + 1], mp[i + 1][j + 1]}; sort(ord.begin(), ord.end()); seg.upd(ord[0], ord[1] - 1, 1); seg.upd(ord[2], ord[3] - 1, inf); } return; } int swap_seats(int a, int b){ vector<int> li = {a, b}; set<pair<int, int> > processed; for(int tp = 0; tp < 2; tp ++){ for(int d = 0; d < 4; d ++){ int mnr = min(r[li[tp]], r[li[tp]] + dx[d]); int mnc = min(c[li[tp]], c[li[tp]] + dy[d]); if(processed.count({mnr, mnc})) continue; processed.insert({mnr, mnc}); if(mnr < 0 || mnc < 0) continue; if(r[li[tp]] + dx[d] > h + 1 || c[li[tp]] + dy[d] > w + 1 ) continue; vector<int> ord = {mp[r[li[tp]]][c[li[tp]]], mp[r[li[tp]] + dx[d]][c[li[tp]]], mp[r[li[tp]]][c[li[tp]] + dy[d]], mp[r[li[tp]] + dx[d]][c[li[tp]] + dy[d]]}; sort(ord.begin(), ord.end()); seg.upd(ord[0], ord[1] - 1, -1); seg.upd(ord[2], ord[3] - 1, -inf); } } swap(mp[r[a]][c[a]], mp[r[b]][c[b]]); swap(r[a], r[b]); swap(c[a], c[b]); processed.clear(); for(int tp = 0; tp < 2; tp ++){ for(int d = 0; d < 4; d ++){ int mnr = min(r[li[tp]], r[li[tp]] + dx[d]); int mnc = min(c[li[tp]], c[li[tp]] + dy[d]); if(processed.count({mnr, mnc})) continue; processed.insert({mnr, mnc}); if(mnr < 0 || mnc < 0) continue; if(r[li[tp]] + dx[d] > h + 1 || c[li[tp]] + dy[d] > w + 1) continue; vector<int> ord = {mp[r[li[tp]]][c[li[tp]]], mp[r[li[tp]] + dx[d]][c[li[tp]]], mp[r[li[tp]]][c[li[tp]] + dy[d]], mp[r[li[tp]] + dx[d]][c[li[tp]] + dy[d]]}; sort(ord.begin(), ord.end()); seg.upd(ord[0], ord[1] - 1, 1); seg.upd(ord[2], ord[3] - 1, inf); } } return seg.cnt[1]; }

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

seats.cpp: In function 'void give_initial_chart(int, int, std::vector<int>, std::vector<int>)':
seats.cpp:102:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |  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...