Submission #605337

#TimeUsernameProblemLanguageResultExecution timeMemory
605337AmirElarbiSeats (IOI18_seats)C++14
17 / 100
4019 ms59472 KiB
#include <bits/stdc++.h> #define vi vector<int> #define ve vector #define ll long long #define vf vector<float> #define vll vector<pair<ll,ll>> #define ii pair<int,int> #define pll pair<ll,ll> #define vvi vector<vi> #define vii vector<ii> #define gii greater<ii> #define pb push_back #define mp make_pair #define fi first #define se second #define INF 2e9+5 #define eps 1e-7 #define eps1 1e-25 #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define MAX_A 1e5+5 #define V 450 using namespace std; const int MOD = 1e9; const int nax = 1e5+5; #include "seats.h" vi r,c; int w,h, cur = 0; vi mn1, mx1, mn2, mx2, res; void give_initial_chart(int H, int W, vi R, vi C) { r = R; c = C; w = W; h = H; mn1.assign(w*h, INF); mx1.assign(w*h, 0); mn2.assign(w*h,INF); mx2.assign(w*h, 0); res.assign(w*h,0); for (int i = 0; i < w*h; ++i) { if(i > 0){ mn1[i] = min(mn1[i-1], r[i]); mx1[i] = max(mx1[i-1], r[i]); mn2[i] = min(mn2[i-1], c[i]); mx2[i] = max(mx2[i-1], c[i]); } else mn1[i] = mx1[i] = r[i], mn2[i] = mx2[i] = c[i]; if( (mx1[i]-mn1[i]+1) * (mx2[i]-mn2[i]+1) == i+1) { res[i] = 1; cur++; } } } int swap_seats(int a, int b) { if(a > b) swap(a,b); swap(r[a], r[b]); swap(c[a], c[b]); for (int i = a; i <= b; ++i) { if(i > 0){ mn1[i] = min(mn1[i-1], r[i]); mx1[i] = max(mx1[i-1], r[i]); mn2[i] = min(mn2[i-1], c[i]); mx2[i] = max(mx2[i-1], c[i]); } else mn1[i] = mx1[i] = r[i], mn2[i] = mx2[i] = c[i]; if( (mx1[i]-mn1[i]+1) * (mx2[i]-mn2[i]+1) == i+1) { if(res[i] == 0) res[i] = 1, cur++; } else if(res[i] == 1) res[i] = 0, cur--; } return cur; }
#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...