제출 #134820

#제출 시각아이디문제언어결과실행 시간메모리
134820Boxworld자리 배치 (IOI18_seats)C++14
25 / 100
4103 ms73804 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].hi=min(A[ls(p)].hi,A[rs(p)].hi); A[p].hx=max(A[ls(p)].hx,A[rs(p)].hx); 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].hi=A[p].hx=P[l].x; A[p].wi=A[p].wx=P[l].y; // printf("BT: p=%d l=%d r=%d hi=%d hx=%d wi=%d wx=%d\n",p,l,r,A[p].hi,A[p].hx,A[p].wi,A[p].wx); 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); // printf("BT: p=%d l=%d r=%d hi=%d hx=%d wi=%d wx=%d\n",p,l,r,A[p].hi,A[p].hx,A[p].wi,A[p].wx); } void update(int p,int l,int r,int ta){ if (l==ta&&ta==r){ A[p].hi=A[p].hx=P[l].x; A[p].wi=A[p].wx=P[l].y; // printf("UD: p=%d l=%d r=%d hi=%d hx=%d wi=%d wx=%d\n",p,l,r,A[p].hi,A[p].hx,A[p].wi,A[p].wx); 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); // printf("UD: p=%d l=%d r=%d hi=%d hx=%d wi=%d wx=%d\n",p,l,r,A[p].hi,A[p].hx,A[p].wi,A[p].wx); } void query(int p,int l,int r,int tl,int tr){ if (tl<=l&&r<=tr){ Hi=min(Hi,A[p].hi); Hx=max(Hx,A[p].hx); Wi=min(Wi,A[p].wi); Wx=max(Wx,A[p].wx); // printf("QY:p=%d l=%d r=%d hi=%d hx=%d wi=%d wx=%d\n",p,l,r,Hi,Hx,Wi,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;){ Hi=P[0].x,Hx=P[0].x,Wi=P[0].y,Wx=P[0].y; query(0,0,h*w-1,0,i); // printf("QY(%d,%d)**:hi=%d hx=%d wi=%d wx=%d\n",0,i,Hi,Hx,Wi,Wx); if ((Hx-Hi+1)*(Wx-Wi+1)==i+1){ans++;i++;} else i=(Hx-Hi+1)*(Wx-Wi+1)-1; } return ans; }

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

seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:62: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...