제출 #607288

#제출 시각아이디문제언어결과실행 시간메모리
607288Koosha_mv자리 배치 (IOI18_seats)C++14
0 / 100
229 ms23788 KiB
#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 upd(int x,int val){
  if(x>0){
    Add(a[x-1],a[x],-1);
  }
  if(x<n-1){
    Add(a[x],a[x+1],-1);
  }
  a[x]=val;
  if(x>0){
    Add(a[x-1],a[x],+1);
  }
  if(x<n-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) {
  upd(A[u],v);
  upd(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
*/
#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...