이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=1e6+99;
int n,m,a[N],lz[N<<2];
pair<int,int> seg[N<<2];
vector<int> A,B;
pair<int,int> operator + (pair<int,int> A,pair<int,int> B){
if(A.F==B.F) A.S+=B.S;
if(A.F<=B.F) return A;
return B;
}
void upd(int id){
seg[id]=seg[id<<1]+seg[id<<1|1];
}
void shift(int id){
lz[id<<1]+=lz[id];
lz[id<<1|1]+=lz[id];
seg[id<<1].F+=lz[id];
seg[id<<1|1].F+=lz[id];
lz[id]=0;
}
void build(int id=1,int l=0,int r=n){
if(l+1==r){
seg[id]=mp(0,1);
return ;
}
int mid=(l+r)>>1;
build(id<<1,l,mid);
build(id<<1|1,mid,r);
upd(id);
}
void add(int L,int R,int val,int id=1,int l=0,int r=n){
if(r<=L || R<=l) return ;
if(L<=l && r<=R){
lz[id]+=val;
seg[id].F+=val;
return ;
}
int mid=(l+r)>>1;
shift(id);
add(L,R,val,id<<1,l,mid);
add(L,R,val,id<<1|1,mid,r);
upd(id);
}
void Add(int l,int r,int val){
if(r<l) swap(l,r);
add(l,r,val);
}
void updcell(int x,int val){
Add(a[x-1],a[x],-1);
Add(a[x],a[x+1],-1);
a[x]=val;
Add(a[x-1],a[x],+1);
Add(a[x],a[x+1],+1);
}
void give_initial_chart(int _n, int _m,vector<int> _A,vector<int> _B) {
n=_n,m=_m;
A=_A,B=_B;
swap(n,m);
swap(A,B);
f(i,0,n) A[i]++,a[A[i]]=i;
a[0]=n,a[n+1]=n;
build();
f(i,0,n+1){
Add(a[i],a[i+1],1);
}
}
int swap_seats(int u, int v) {
//eror(A[u]);
//eror(A[v]);
updcell(A[u],v);
updcell(A[v],u);
swap(A[u],A[v]);
return seg[1].S*(seg[1].F==2);
}
/*
1 4 1
0 1
0 0
0 3
0 2
0 0
1 4 4
0 0
0 1
0 2
0 3
0 1
0 3
1 3
1 2
*/
# | 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... |