제출 #134825

#제출 시각아이디문제언어결과실행 시간메모리
134825Boxworld자리 배치 (IOI18_seats)C++14
0 / 100
4098 ms56756 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; const int maxN=1000100; int h,w,Hi,Hx,Wi,Wx; struct point{int x,y;}P[maxN]; struct node{int hi,hx,wi,wx;}A[maxN*4]; inline int ls(int p){return p*2+1;} inline int rs(int p){return p*2+2;} void push_up(int p){ A[p].wi=min(A[ls(p)].wi,A[rs(p)].wi); A[p].wx=max(A[ls(p)].wx,A[rs(p)].wx); } void build(int p,int l,int r){ if (l==r){ A[p].wi=A[p].wx=P[l].y; return; } int m=(l+r)/2; if (l<=m)build(ls(p),l,m); if (m<r)build(rs(p),m+1,r); push_up(p); } void update(int p,int l,int r,int ta){ if (l==ta&&ta==r){ A[p].wi=A[p].wx=P[l].y; return; } int m=(l+r)/2; if (l<=ta&&ta<=m)update(ls(p),l,m,ta); if (m+1<=ta&&ta<=r)update(rs(p),m+1,r,ta); push_up(p); } void query(int p,int l,int r,int tl,int tr){ if (tl<=l&&r<=tr){ Wi=min(Wi,A[p].wi); Wx=max(Wx,A[p].wx); return; } int m=(l+r)/2; if (tl<=m)query(ls(p),l,m,tl,tr); if (m<tr)query(rs(p),m+1,r,tl,tr); } void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { h=H;w=W; for (int i=0;i<H*W;i++){P[i].x=R[i];P[i].y=C[i];} build(0,0,h*w-1); } int swap_seats(int a, int b){ int t=a,ans=0; swap(P[a],P[b]); update(0,0,h*w-1,a); update(0,0,h*w-1,b); for (int i=0;i<h*w;){ Wi=P[0].y,Wx=P[0].y; query(0,0,h*w-1,0,i); if (Wx-Wi+1==i){ans++;i++;} else i=Wx-Wi; } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:51:6: warning: unused variable 't' [-Wunused-variable]
  int t=a,ans=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...