제출 #116233

#제출 시각아이디문제언어결과실행 시간메모리
116233zubec자리 배치 (IOI18_seats)C++14
100 / 100
3252 ms104312 KiB
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;

std::vector<int> r;

const int SZ = 1000100;

pair<int, int> t[SZ*4];

int ob[SZ*4];

vector <vector<int> > arr;

void build(int v, int l, int r){
    if (l == r){
        t[v].second = 1;
        return;
    }
    int mid = (l+r)>>1;
    build(v+v, l, mid);
    build(v+v+1, mid+1, r);
    t[v].second = t[v+v].second + t[v+v+1].second;
}

void push(int v){
    if (ob[v] == 0)
        return;
    t[v+v].first += ob[v];
    t[v+v+1].first += ob[v];
    ob[v+v] += ob[v];
    ob[v+v+1] += ob[v];
    ob[v] = 0;
}

void update(int v, int l, int r, int tl, int tr, int x){
    if (l > r || tl > r || l > tr || tl > tr)
        return;
    if (tl <= l && r <= tr){
        t[v].first += x;
        ob[v] += x;
        return;
    }
    int mid = (l+r)>>1;
    push(v);
    update(v+v, l, mid, tl, tr, x);
    update(v+v+1, mid+1, r, tl, tr, x);
    if (t[v+v].first < t[v+v+1].first){
        t[v] = t[v+v];
    } else
    if (t[v+v].first > t[v+v+1].first){
        t[v] = t[v+v+1];
    } else {
        t[v] = {t[v+v].first, t[v+v].second + t[v+v+1].second};
    }
}

int inf;

vector <int> R, C;

void upd(int x, int y, int add){
    update(1, 1, inf, arr[x][y] + 1, min({arr[x+1][y], arr[x][y+1], arr[x+1][y+1]}), add);
    update(1, 1, inf, arr[x+1][y] + 1, min({arr[x][y], arr[x][y+1], arr[x+1][y+1]}), add);
    update(1, 1, inf, arr[x][y+1] + 1, min({arr[x][y], arr[x+1][y], arr[x+1][y+1]}), add);
    update(1, 1, inf, arr[x+1][y+1] + 1, min({arr[x][y], arr[x+1][y], arr[x][y+1]}), add);
    update(1, 1, inf, max({arr[x+1][y], arr[x][y+1], arr[x+1][y+1]}) + 1, arr[x][y], add);
    update(1, 1, inf, max({arr[x][y], arr[x][y+1], arr[x+1][y+1]}) + 1, arr[x+1][y], add);
    update(1, 1, inf, max({arr[x][y], arr[x+1][y], arr[x+1][y+1]}) + 1, arr[x][y+1], add);
    update(1, 1, inf, max({arr[x][y], arr[x+1][y], arr[x][y+1]}) + 1, arr[x+1][y+1], add);
}

void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
    ::R = R;
    ::C = C;
    inf = H*W;
    arr.resize(H+2, vector<int>(W+2, inf));
    for (int i = 0; i < H*W; i++){
        arr[R[i]+1][C[i]+1] = i;
    }
    build(1, 1, inf);

    for (int i = 0; i + 1 < arr.size(); i++){
        for (int j = 0; j + 1 < arr[i].size(); j++){
            upd(i, j, 1);
        }
    }

}


int swap_seats(int a, int b) {
    int x1 = R[a]+1, y1 = C[a]+1, x2 = R[b]+1, y2 = C[b]+1;
    swap(R[a], R[b]);
    swap(C[a], C[b]);
    map<pair<int, int>, int> mp1;
    mp1[{x1-1, y1-1}] = 1;
    mp1[{x1-1, y1}] = 1;
    mp1[{x1, y1-1}] = 1;
    mp1[{x1, y1}] = 1;
    mp1[{x2-1, y2-1}] = 1;
    mp1[{x2-1, y2}] = 1;
    mp1[{x2, y2-1}] = 1;
    mp1[{x2, y2}] = 1;
    for (auto it = mp1.begin(); it != mp1.end(); it++){
        int x = it->first.first, y = it->first.second;
        upd(x, y, -1);
    }
    swap(arr[x1][y1], arr[x2][y2]);
    for (auto it = mp1.begin(); it != mp1.end(); it++){
        int x = it->first.first, y = it->first.second;
        upd(x, y, 1);
    }

    return t[1].second;
}

/**

0 3 4
1 2 5

2 3 2
0 0
1 0
1 1
0 1
0 2
1 2
0 5
0 5

*/

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

seats.cpp: In function 'void give_initial_chart(int, int, std::vector<int>, std::vector<int>)':
seats.cpp:83:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i + 1 < arr.size(); i++){
                     ~~~~~~^~~~~~~~~~~~
seats.cpp:84:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j + 1 < arr[i].size(); j++){
                         ~~~~~~^~~~~~~~~~~~~~~
#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...