This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "seats.h"
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll x[2][1010101],n,i,j;
ll ST[2][2][4040404];
void upd(ll aa,ll bb,ll cc,ll dd,ll ee)
{
if(aa==bb)
{
ST[0][dd][ee]=x[dd][aa];
ST[1][dd][ee]=x[dd][aa];
}
else
{
ll ce=(aa+bb)/2;
if(cc<=ce)
upd(aa,ce,cc,dd,ee*2);
else
upd(ce+1,bb,cc,dd,ee*2+1);
ST[0][dd][ee]=min(ST[0][dd][ee*2],ST[0][dd][ee*2+1]);
ST[1][dd][ee]=max(ST[1][dd][ee*2],ST[1][dd][ee*2+1]);
}
}
ll quemi(ll aa,ll bb,ll cc,ll dd,ll ee,ll ff)
{
if(bb<cc||dd<aa)
return 1e18;
else
if(cc<=aa&&bb<=dd)
return ST[0][ff][ee];
else
{
ll ce=(aa+bb)/2;
return min(quemi(aa,ce,cc,dd,ee*2,ff),quemi(ce+1,bb,cc,dd,ee*2+1,ff));
}
}
ll quema(ll aa,ll bb,ll cc,ll dd,ll ee,ll ff)
{
if(bb<cc||dd<aa)
return -1e18;
else
if(cc<=aa&&bb<=dd)
return ST[1][ff][ee];
else
{
ll ce=(aa+bb)/2;
return max(quema(aa,ce,cc,dd,ee*2,ff),quema(ce+1,bb,cc,dd,ee*2+1,ff));
}
}
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C)
{
n=H*W;
for(i=0;i<H*W;i++)
{
x[0][i]=R[i];
x[1][i]=C[i];
upd(0,n-1,i,0,1);
upd(0,n-1,i,1,1);
}
}
int swap_seats(int a, int b)
{
swap(x[1][a],x[1][b]);
swap(x[0][a],x[0][b]);
upd(0,n-1,a,0,1);
upd(0,n-1,a,1,1);
upd(0,n-1,b,0,1);
upd(0,n-1,b,1,1);
ll hz=0;
//cout<<"A";
//return 0;
ll too=0;
for(i=0;i<n;i++)
{
too++;
ll mx=quemi(0,n-1,0,i,1,0);
ll my=quemi(0,n-1,0,i,1,1);
ll Mx=quema(0,n-1,0,i,1,0);
ll My=quema(0,n-1,0,i,1,1);
ll tem=(Mx-mx+1)*(My-my+1);
if(tem==i+1)hz++;
i=max(i,i+min((Mx-mx+1),(My-my+1))-3);
}
if(too>2020)n/=0;
return hz;
}
Compilation message (stderr)
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:89:15: warning: division by zero [-Wdiv-by-zero]
if(too>2020)n/=0;
~^~~
# | 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... |