QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#439643 | #8711. Tiles | A_zjzj | 4 | 113ms | 40364kb | C++17 | 4.7kb | 2024-06-12 15:24:31 | 2024-06-12 15:24:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
const int N=2e5+10,M=N*2;
int n;
struct node{
int x,y;
}a[N];
ll cross(node a,node b){
return 1ll*a.x*b.y-1ll*a.y*b.x;
}
vector<int>nx,ny;
using vec=array<int,4>;
#ifdef DEBUG
ostream& operator << (ostream &out,vec a){
out<<'[';
for(auto x:a)out<<x<<',';
return out<<']';
}
#endif
namespace SGT1{
const vec I={0,1,2,3};
vec operator + (const vec &a,const vec &b){
static vec c;
for(int i=0;i<4;i++)c[i]=a[i]+b[i];
return c;
}
vec merge(const vec &a,const vec &b){
static vec c;
for(int i=0;i<4;i++)c[i]=b[a[i]];
return c;
}
vec Merge(const vec &a,const vec &b){
static vec c;
c.fill(0);
for(int i=0;i<4;i++)c[b[i]]+=a[i];
return c;
}
vec t[M<<2],laz[M<<2];
void pushup(int rt){
t[rt]=t[rt<<1]+t[rt<<1|1];
}
void pushlaz(int rt,vec x){
t[rt]=Merge(t[rt],x);
laz[rt]=merge(laz[rt],x);
}
void pushdown(int rt){
if(laz[rt]!=I){
pushlaz(rt<<1,laz[rt]);
pushlaz(rt<<1|1,laz[rt]);
laz[rt]=I;
}
}
void build(int l=0,int r=ny.size()-2,int rt=1){
laz[rt]=I;
if(l==r)return t[rt][0]=ny[l+1]-ny[l],void();
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
pushup(rt);
}
void update(int L,int R,vec x,int l=0,int r=ny.size()-2,int rt=1){
// if(rt==1)debug("update",L,R,x);
if(L<=l&&r<=R)return pushlaz(rt,x);
int mid=(l+r)>>1;
pushdown(rt);
if(L<=mid)update(L,R,x,l,mid,rt<<1);
if(mid<R)update(L,R,x,mid+1,r,rt<<1|1);
pushup(rt);
}
vec query(int L=0,int R=ny.size()-2,int l=0,int r=ny.size()-2,int rt=1){
if(L<=l&&r<=R)return t[rt];
int mid=(l+r)>>1;
pushdown(rt);
if(R<=mid)return query(L,R,l,mid,rt<<1);
if(mid<L)return query(L,R,mid+1,r,rt<<1|1);
return query(L,R,l,mid,rt<<1)+query(L,R,mid+1,r,rt<<1|1);
}
}
namespace SGT2{
struct node{
int st,ed,cnt;
bool f,g;
};
node operator + (const node &a,const node &b){
if(a.st==-1)return b;
if(b.st==-1)return a;
if(a.cnt%2==0)return {a.st,b.ed,a.cnt+b.cnt,a.f&&b.f,a.g&&b.g&&(b.st-a.ed)%2==0};
else return {a.st,b.ed,a.cnt+b.cnt,a.f&&b.g&&(b.st-a.ed)%2==0,a.g&&b.f};
}
node t[M<<2];
void pushup(int rt){
t[rt]=t[rt<<1]+t[rt<<1|1];
}
void build(int l=0,int r=ny.size()-1,int rt=1){
t[rt]={-1,-1,0,0,0};
if(l==r)return;
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
}
void update(int x,int l=0,int r=ny.size()-1,int rt=1){
// if(rt==1)debug("update",x);
if(l==r){
if(t[rt].st==-1)t[rt]={ny[l],ny[l],1,1,1};
else t[rt]={-1,-1,0,0,0};
return;
}
int mid=(l+r)>>1;
if(x<=mid)update(x,l,mid,rt<<1);
else update(x,mid+1,r,rt<<1|1);
pushup(rt);
}
bool query(){
return t[1].f;
}
}
vector<pair<int,int>>o1[M],o2[M];
int main(){
scanf("%d%*d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&a[i].x,&a[i].y);
}
if([&](){
ll s=0;
for(int i=1;i<=n;i++){
s+=cross(a[i],a[i%n+1]);
}
return s<0;
}())reverse(a+1,a+1+n);
for(int i=1;i<=n;i++){
nx.push_back(a[i].x);
ny.push_back(a[i].y);
}
sort(all(nx)),nx.erase(unique(all(nx)),nx.end());
sort(all(ny)),ny.erase(unique(all(ny)),ny.end());
for(int i=1;i<=n;i++){
a[i].x=lower_bound(all(nx),a[i].x)-nx.begin();
a[i].y=lower_bound(all(ny),a[i].y)-ny.begin();
}
for(int i=1;i<=n;i++){
if(a[i].x==a[(i+n-2)%n+1].x)continue;
int st=a[i].y,ed=a[i].y;
for(int j=i;a[j].x==a[i].x;j=j%n+1)ed=a[j].y;
// debug(a[i].x,st,ed);
if(st>ed){
o1[a[i].x].push_back({ed,st});
}else{
o2[a[i].x].push_back({st,ed});
}
}
int ans=0;
SGT1::build();
SGT2::build();
// debug(nx,ny);
for(int i=0;i+1<nx.size();i++){
if(![&](){
for(auto [l,r]:o1[i]){
// debug("add",i,l,r);
SGT1::update(l,r-1,vec({1,1,3,3}));
SGT2::update(l),SGT2::update(r);
if(!SGT2::query())return 0;
}
for(auto [l,r]:o2[i]){
// debug("del",i,l,r);
auto res=SGT1::query(l,r-1);
if(res[2]||res[3])return 0;
SGT1::update(l,r-1,vec({0,0,2,2}));
SGT2::update(l),SGT2::update(r);
if(!SGT2::query())return 0;
}
int d=nx[i+1]-nx[i];
static vec t={0,3,2,1};
if(d%2==0)SGT1::update(0,ny.size()-2,t);
auto res=SGT1::query();
// debug(i,res);
if(!res[2]&&!res[3])ans=nx[i+1]-1;
SGT1::update(0,ny.size()-2,t);
res=SGT1::query();
// debug(i,res);
if(!res[2]&&!res[3])ans=nx[i+1];
return 1;
}())break;
}
cout<<ans<<endl;
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
詳細信息
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 0ms
memory: 24564kb
input:
4 3 0 0 0 3 3 3 3 0
output:
0
result:
ok single line: '0'
Test #2:
score: 4
Accepted
time: 2ms
memory: 24472kb
input:
4 999999999 999999999 0 999999999 1000000000 0 1000000000 0 0
output:
999999998
result:
ok single line: '999999998'
Test #3:
score: 4
Accepted
time: 4ms
memory: 22460kb
input:
4 875 875 0 0 0 0 284 875 284
output:
874
result:
ok single line: '874'
Test #4:
score: 4
Accepted
time: 3ms
memory: 22552kb
input:
4 317 317 0 317 920 0 920 0 0
output:
316
result:
ok single line: '316'
Test #5:
score: 4
Accepted
time: 4ms
memory: 24560kb
input:
4 912 912 814 912 0 0 0 0 814
output:
912
result:
ok single line: '912'
Test #6:
score: 4
Accepted
time: 0ms
memory: 24632kb
input:
4 2 0 0 0 1 2 1 2 0
output:
0
result:
ok single line: '0'
Test #7:
score: 4
Accepted
time: 0ms
memory: 22512kb
input:
4 1 0 0 0 1 1 1 1 0
output:
0
result:
ok single line: '0'
Test #8:
score: 4
Accepted
time: 3ms
memory: 24636kb
input:
4 412 412 998 0 998 0 17 412 17
output:
0
result:
ok single line: '0'
Test #9:
score: 4
Accepted
time: 7ms
memory: 22596kb
input:
4 87523458 87523458 42385699 0 42385699 0 23498231 87523458 23498231
output:
87523458
result:
ok single line: '87523458'
Test #10:
score: 4
Accepted
time: 4ms
memory: 24624kb
input:
4 1 0 0 0 1000000000 1 1000000000 1 0
output:
0
result:
ok single line: '0'
Test #11:
score: 4
Accepted
time: 0ms
memory: 24640kb
input:
4 1000000000 1000000000 0 1000000000 1000000000 0 1000000000 0 0
output:
1000000000
result:
ok single line: '1000000000'
Subtask #2:
score: 0
Runtime Error
Dependency #1:
100%
Accepted
Test #12:
score: 0
Runtime Error
input:
5 29034873 29034873 13721 0 13721 0 99198237 29034870 99198237 29034873 99198237
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #32:
score: 0
Runtime Error
input:
1551 1000 0 988 2 988 3 988 6 988 6 985 6 982 6 981 6 979 6 978 6 977 6 976 6 975 6 974 6 972 6 970 6 969 6 968 6 966 6 965 6 964 7 964 8 964 8 963 8 961 8 960 10 960 11 960 13 960 16 960 16 959 16 958 16 957 16 954 16 953 16 951 16 950 17 950 18 950 18 948 18 946 18 945 18 944 18 942 18 941 18 939 ...
output:
result:
Subtask #4:
score: 0
Wrong Answer
Test #45:
score: 19
Accepted
time: 5ms
memory: 24556kb
input:
14 6 0 1 0 3 2 3 2 4 0 4 0 6 3 6 3 7 4 7 6 7 6 5 3 5 3 2 3 1
output:
2
result:
ok single line: '2'
Test #46:
score: 0
Wrong Answer
time: 4ms
memory: 24404kb
input:
18 9 0 2 2 2 2 1 4 1 4 0 9 0 9 2 4 2 4 4 7 4 7 3 9 3 9 6 4 6 4 5 2 5 2 4 0 4
output:
2
result:
wrong answer 1st lines differ - expected: '6', found: '2'
Subtask #5:
score: 0
Runtime Error
Test #89:
score: 22
Accepted
time: 45ms
memory: 26496kb
input:
199996 198506138 31225688 248200160 31225688 248291950 28995282 248291950 28995282 248200160 26764876 248200160 26764876 248291950 24534470 248291950 24534470 248200160 22304064 248200160 22304064 248291950 20073658 248291950 20073658 248200160 17843252 248200160 17843252 248291950 15612846 24829195...
output:
0
result:
ok single line: '0'
Test #90:
score: 22
Accepted
time: 42ms
memory: 27032kb
input:
199996 740789144 48843244 341844840 48843244 342042210 40702704 342042210 40702704 341844840 32562164 341844840 32562164 342042210 24421624 342042210 24421624 341844840 16281084 341844840 16281084 342042210 8140544 342042210 8140544 341450100 16281084 341450100 16281084 341647470 24421624 341647470 ...
output:
0
result:
ok single line: '0'
Test #91:
score: 22
Accepted
time: 78ms
memory: 27196kb
input:
199996 198506138 31225684 248200166 31225684 248291956 28995278 248291956 28995278 248200166 26764872 248200166 26764872 248291956 24534466 248291956 24534466 248200166 22304060 248200166 22304060 248291956 20073654 248291956 20073654 248200166 17843248 248200166 17843248 248291956 15612842 24829195...
output:
198506134
result:
ok single line: '198506134'
Test #92:
score: 22
Accepted
time: 79ms
memory: 26412kb
input:
199996 740789144 48843240 341844840 48843240 342042210 40702700 342042210 40702700 341844840 32562160 341844840 32562160 342042210 24421620 342042210 24421620 341844840 16281080 341844840 16281080 342042210 8140540 342042210 8140540 341450100 16281080 341450100 16281080 341647470 24421620 341647470 ...
output:
740789140
result:
ok single line: '740789140'
Test #93:
score: 0
Runtime Error
input:
199999 1000000000 1000000000 0 999999222 0 999999222 136 999984018 136 999984018 228 999973482 228 999973482 292 999971160 292 999971160 396 999964886 396 999964886 588 999959042 588 999959042 680 999955190 680 999955190 732 999927188 732 999927188 748 999913912 748 999913912 796 999912122 796 99991...
output:
result:
Subtask #6:
score: 0
Wrong Answer
Test #118:
score: 25
Accepted
time: 52ms
memory: 40364kb
input:
200000 1000000000 1000000000 0 999990876 0 999990876 38 999972524 38 999972524 1510 999969180 1510 999969180 3734 999964780 3734 999964780 4138 999960464 4138 999960464 11052 999953728 11052 999953728 24478 999914972 24478 999914972 25892 999909864 25892 999909864 28102 999902920 28102 999902920 301...
output:
40502
result:
ok single line: '40502'
Test #119:
score: 25
Accepted
time: 113ms
memory: 34312kb
input:
200000 778696306 22822858 87970191 330038016 87970191 330038016 87957657 259262362 87957657 259262362 87923225 316313936 87923225 316313936 87896643 155653960 87896643 155653960 87890367 184851800 87890367 184851800 87877609 93595576 87877609 93595576 87838069 384366344 87838069 384366344 87822439 3...
output:
298364980
result:
ok single line: '298364980'
Test #120:
score: 0
Wrong Answer
time: 73ms
memory: 39616kb
input:
199996 939450484 183372590 726043385 183372590 947636904 183351398 947636904 183351398 585647776 183326398 585647776 183326398 815654133 183324414 815654133 183324414 681316487 183304068 681316487 183304068 993350372 183281288 993350372 183281288 748476649 183258832 748476649 183258832 772289334 183...
output:
35398
result:
wrong answer 1st lines differ - expected: '158652', found: '35398'
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%