#include "seats.h"
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vc vector<char>
#define vb vector<bool>
#define mii map<int,int>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define in(a) int a; cin>>a
#define in2(a,b) int a,b; cin>>a>>b
#define in3(a,b,c) int a,b,c; cin>>a>>b>>c
#define in4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d
#define vin(v,n); vi v(n); f0r(i,n){cin>>v[i];}
#define out(a) cout<<a<<'\n'
#define out2(a,b) cout<<a<<' '<<b<<'\n'
#define out3(a,b,c) cout<<a<<' '<<b<<' '<<c<<'\n'
#define out4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<'\n'
#define pout(a) cout<<a.first<<' '<<a.second<<'\n'
#define vout(v) for(auto u : v){cout<<u<<' ';} cout<<'\n'
#define dout(a) cout<<a<<' '<<#a<<'\n'
#define dout2(a,b) cout<<a<<' '<<#a<<' '<<b<<' '<<#b<<'\n'
#define yn(x); if(x){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';}
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> os;
vector<os>rows;
vector<os>cols;
vpii pts;
int N, H, W;
void give_initial_chart(signed H, signed W, std::vector<signed> R, std::vector<signed> C) {
::N=H*W; ::H=H; ::W=W;
rows.resize(H); cols.resize(W);
f0r(i,N){
rows[R[i]].insert(i);
cols[C[i]].insert(i);
pts.pb(mp(R[i], C[i]));
}
}
signed swap_seats(signed a, signed b) {
rows[pts[a].first].erase(a);
rows[pts[b].first].erase(b);
cols[pts[a].second].erase(a);
cols[pts[b].second].erase(b);
swap(pts[a], pts[b]);
rows[pts[a].first].insert(a);
rows[pts[b].first].insert(b);
cols[pts[a].second].insert(a);
cols[pts[b].second].insert(b);
vector<pair<pii,int>> g;
f0r(i, H){
g.pb(mp(mp(*rows[i].find_by_order(0), i), 0));
}
f0r(i, W){
g.pb(mp(mp(*cols[i].find_by_order(0), i), 1));
}
sort(all(g));
int ax = 4e18; int bx = -4e18;
int ay = 4e18; int by = -4e18;
int ans = 0;
f0r(i,g.size()){
bool cj = 0;
int t = g[i].second;
int num = g[i].first.first;
int dex = g[i].first.second;
if(t == 0){
if(dex < ax){
cj = 1; ax = dex;
}
if(dex > bx){
cj = 1; bx = dex;
}
}
else{
if(dex < ay){
cj = 1; ay = dex;
}
if(dex > by){
cj = 1; by = dex;
}
}
if(i == g.size() - 1 || g[i+1].first.first + 1 > (bx-ax+1) * (by-ay+1)){
ans++;
}
}
return ans;
return 0;
}
Compilation message (stderr)
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:69:18: warning: overflow in conversion from 'double' to 'int' changes value from '4.0e+18' to '2147483647' [-Woverflow]
69 | int ax = 4e18; int bx = -4e18;
| ^~~~
seats.cpp:69:33: warning: overflow in conversion from 'double' to 'int' changes value from '-4.0e+18' to '-2147483648' [-Woverflow]
69 | int ax = 4e18; int bx = -4e18;
| ^~~~~
seats.cpp:70:18: warning: overflow in conversion from 'double' to 'int' changes value from '4.0e+18' to '2147483647' [-Woverflow]
70 | int ay = 4e18; int by = -4e18;
| ^~~~
seats.cpp:70:33: warning: overflow in conversion from 'double' to 'int' changes value from '-4.0e+18' to '-2147483648' [-Woverflow]
70 | int ay = 4e18; int by = -4e18;
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |