제출 #256847

#제출 시각아이디문제언어결과실행 시간메모리
256847Hehehe자리 배치 (IOI18_seats)C++14
컴파일 에러
0 ms0 KiB
#include "seats.h" #include <bits/stdc++.h> #define x first #define y second #define ff first #define ss second using namespace std; const int NMAX = 4000005; const int dxa[] = {1, 0, -1, 0}; const int dya[] = {0, 1, 0, -1}; typedef pair<int, int> pii; pii t[4*NMAX]; int lz[4*NMAX]; pii seats[4000555]; int tsz, H, W; void updateA(pii pos); void deleteA(pii pos); void updateB(pii pos); void deleteB(pii pos); int secondSmallestNeighbour(pii pos); pii getB(pii pos); bool ok(pii pos); void addInterval(int l, int r); void subInterval(int l, int r); void rewrite(pii pos, int val); vector<vector<int>> arr; int ln(int n){ return 2*n; } int rn(int n){ return 2*n + 1; } pii merge(pii a, pii b){ if(a.ff < b.ff)return a; if(a.ff > b.ff)return b; return {a.ff, a.ss + b.ss}; } void push(int v){ if(!lz[v])return; t[2*v].ff += lz[v]; t[2*v + 1].ff += lz[v]; lz[2*v] += lz[v]; lz[2*v + 1] += lz[v]; lz[v] = 0; } void build(int v, int l, int r){ if(l == r){ t[v] = {0, 1}; return; } int mid = (l + r) >> 1; build(2*v, l, mid); build(2*v + 1, mid + 1, r); t[v] = merge(t[2*v], t[2*v + 1]); } void update(int v, int tl, int tr, int l, int r, int add){ push(v); if(tl > r || tr < l)return; if(l <= tl && tr <= r){ lazy[v] += add; t[v].ff += add; push(v); return; } push(v); int mid = (tl + tr) >> 1; if(l <= mid)update(2*v, tl, mid, l, r, add); if(r > mid)update(2*v + 1, mid + 1, tr, l, r, add); t[v] = merge(t[2*v], t[2*v + 1]); } void give_initial_chart(int _H, int _W, vector<int> R, vector<int> C) { W = _W; H = _H; tsz = H*W; build(1, 1, tsz); arr = vector<vector<int>>(H+1, vector<int>(W+1, 0)); for(int i=0; i<H*W; ++i){ arr[R[i] + 1][C[i] + 1] = i + 1; seats[i] = {R[i] + 1, C[i] + 1}; } for(int i = 1; i<=H; ++i){ for(int j = 1; j<=W; ++j){ updateA({i, j}); updateB({i, j}); } } } int swap_seats(int a, int b) { pii pa = seats[a]; pii pb = seats[b]; rewrite(pa, b + 1); rewrite(pb, a + 1); swap(seats[a], seats[b]); return (t[1].first == 1 ? t[1].second : 0); } void rewrite(pii pos, int val){ // delete previous connections deleteA(pos); for(int i=0; i<4; ++i){ pii aux = pos; aux.x += dxa[i]; aux.y += dya[i]; if(ok(aux)){ deleteA(aux); } } deleteB(pos); for(int i=2; i<4; ++i){ pii aux = pos; aux.x += dxa[i]; aux.y += dya[i]; if(ok(aux)){ deleteB(aux); } } arr[pos.x][pos.y] = val; updateA(pos); for(int i=0; i<4; ++i){ pii aux = pos; aux.x += dxa[i]; aux.y += dya[i]; if(ok(aux)){ updateA(aux); } } updateB(pos); for(int i=2; i<4; ++i){ pii aux = pos; aux.x += dxa[i]; aux.y += dya[i]; if(ok(aux)){ updateB(aux); } } } void deleteA(pii pos){ int l = secondSmallestNeighbour(pos); int r = arr[pos.x][pos.y]; if(r > l){ subInterval(l, r - 1); } } void updateA(pii pos){ int l = secondSmallestNeighbour(pos); int r = arr[pos.x][pos.y]; if(r > l){ addInterval(l, r - 1); } } void deleteB(pii pos){ pii p = getB(pos); if(p.y > p.x){ subInterval(p.x, p.y - 1); } } void updateB(pii pos){ pii p = getB(pos); if(p.y > p.x){ addInterval(p.x, p.y - 1); } } int secondSmallestNeighbour(pii pos){ set<int> countSet; for(int i=0; i<4; ++i){ pii aux = pos; aux.x += dxa[i]; aux.y += dya[i]; if(ok(aux)){ countSet.insert(arr[aux.x][aux.y]); } } if(countSet.size() > 1){ return *(++countSet.begin()); } else { return tsz+1; } } pii getB(pii pos){ int l = arr[pos.x][pos.y]; int r = tsz + 1; for(int i=0; i<4; ++i){ pii aux = pos; aux.x += dxa[i]; aux.y += dya[i]; if(ok(aux)){ if(i < 2) r = min(r, arr[aux.x][aux.y]); } } return {l, r}; } bool ok(pii pos){ if(pos.x > 0 && pos.x <= H){ if(pos.y > 0 && pos.y <= W){ return 1; } } return 0; } void addInterval(int l, int r){ update(1, 1, tsz, l, r, +1); } void subInterval(int l, int r){ update(1, 1, tsz, l, r, -1); }

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

seats.cpp: In function 'void update(int, int, int, int, int, int)':
seats.cpp:77:9: error: 'lazy' was not declared in this scope
         lazy[v] += add;
         ^~~~
seats.cpp:77:9: note: suggested alternative: 'lz'
         lazy[v] += add;
         ^~~~
         lz