Submission #623228

#TimeUsernameProblemLanguageResultExecution timeMemory
623228Ronin13Seats (IOI18_seats)C++14
0 / 100
3428 ms55352 KiB
#include "seats.h"
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;


std::vector<int> r;
std :: vector <int> c;

const int NMAX = 1e6 + 1;
int cnt = 0;

int mxx[NMAX], mnx[NMAX], mny[NMAX], mxy[NMAX];

void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
    r = R;
    c = C;
    int n = H, m = W;
    for(int i = 0; i < n * m; i++){
        if(i == 0){
            mxx[i] = r[i];
            mnx[i] = r[i];
            mny[i] = c[i];
            mxy[i] = c[i];
        }
        else{
            mxx[i] = max(mxx[i - 1], r[i]);
            mnx[i] = min(mnx[i - 1], r[i]);
            mxy[i] = max(mxy[i - 1], c[i]);
            mny[i] = min(mny[i - 1], c[i]);
        }
        int v = mxx[i] - mnx[i] + 1;
        int u = mxy[i] - mny[i] + 1;
        if(v * u == i + 1) cnt++;
    }
}

int swap_seats(int a, int b) {
    for(int i = a; i <= b; i++){
        int v = mxx[i] - mnx[i] + 1;
        int u = mxy[i] - mny[i] + 1;
        if(v * u == i + 1) cnt--;
    }
    swap(r[a], r[b]);
    swap(c[a], c[b]);
    for(int i = a; i <= b; i++){
        if(i == 0){
            mxx[i] = r[i];
            mnx[i] = r[i];
            mny[i] = c[i];
            mxy[i] = c[i];
        }
        else{
            mxx[i] = max(mxx[i - 1], r[i]);
            mnx[i] = min(mnx[i - 1], r[i]);
            mxy[i] = max(mxy[i - 1], c[i]);
            mny[i] = min(mny[i - 1], c[i]);
        }
        int v = mxx[i] - mnx[i] + 1;
        int u = mxy[i] - mny[i] + 1;
        if(v * u == i + 1) cnt++;
    }
    return cnt;
}
#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...