Submission #134844

#TimeUsernameProblemLanguageResultExecution timeMemory
134844BoxworldSeats (IOI18_seats)C++14
11 / 100
4038 ms48632 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; const int maxN=1000100; struct node{int x,y,hi,hx,wi,wx,ans;}p[maxN]; int h,w; 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]; } p[0].hi=p[0].hx=p[0].x; p[0].wi=p[0].wx=p[0].y; for (int i=1;i<h*w;i++){ p[i].hi=min(p[i].x,p[i-1].hi); p[i].hx=max(p[i].x,p[i-1].hx); p[i].wi=min(p[i].y,p[i-1].wi); p[i].wx=max(p[i].y,p[i-1].wx); } } int swap_seats(int a, int b){ int t=a,ans=0; swap(p[a],p[b]); p[0].hi=p[0].hx=p[0].x; p[0].wi=p[0].wx=p[0].y; int mi=min(a,b); if(mi==0)mi=1; for (int i=mi;i<=max(a,b);i++){ p[i].hi=min(p[i].x,p[i-1].hi); p[i].hx=max(p[i].x,p[i-1].hx); p[i].wi=min(p[i].y,p[i-1].wi); p[i].wx=max(p[i].y,p[i-1].wx); } for (int i=0;i<h*w;){ int Hi=p[i].hi,Hx=p[i].hx,Wi=p[i].wi,Wx=p[i].wx; if ((Hx-Hi+1)*(Wx-Wi+1)==i+1){ans++;i++;} else i=(Hx-Hi+1)*(Wx-Wi+1)-1; } return ans; }

Compilation message (stderr)

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