QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#640456 | #7038. Carpets Removal | Icedpiggy | AC ✓ | 1239ms | 213652kb | C++14 | 3.0kb | 2024-10-14 12:50:28 | 2024-10-14 12:50:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define i128 __int128
char buf[1<<21],*rp1=buf,*rp2=buf;
#define getchar() (rp1==rp2&&(rp2=(rp1=buf)+fread(buf,1,1<<21,stdin),rp1==rp2)?EOF:*rp1++)
inline i64 rd()
{
i64 num=0;char ch=getchar();bool op=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')op=1;
for(;isdigit(ch);ch=getchar())num=num*10+(ch-'0');
return op?-num:num;
}
inline void Max(int &x,int v){if(x<v)x=v;}
template<typename T>
inline void operator += (vector<T>&A,const T&v){A.emplace_back(v);}
const int N=3e5+10,M=1505;
#define pii pair<int,int>
#define fi first
#define se second
int n,m,w=0;
pii a[M][M];
int Sum[N];
struct P{int l,r,v;};
vector<P> A[M],B[M];
map<int,int> s[N];
int cnt=0,Ans=0;
inline void upd(pii &res,int x)
{
if(res.fi!=0)
res=pii(-1,-1);
else if(res.se!=0)
res.fi=x;
else
res.se=x;
}
struct Seg
{
#define ls (p<<1)
#define rs (p<<1|1)
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define dmid int mid=(l+r)>>1
#define root 1,m,1
int tag[1<<12|3];
bitset<N> t[1<<12|3];
vector<int> s[1<<12|3];
inline void reset(int p)
{
vector<int> st;
while(!s[p].empty())
{
int x=s[p].back();s[p].pop_back();
if(t[p][x])st+=x;
}
s[p].swap(st);
}
inline void ins(int L,int R,int v,int l,int r,int p)
{
if(L<=l&&r<=R){t[p][v]=1,tag[p]++,s[p]+=v;return;}
dmid;if(L<=mid)ins(L,R,v,lson);if(mid<R)ins(L,R,v,rson);
}
inline void del(int L,int R,int v,int l,int r,int p)
{
if(L<=l&&r<=R){t[p][v]=0,tag[p]--;return;}
dmid;if(L<=mid)del(L,R,v,lson);if(mid<R)del(L,R,v,rson);
}
inline void mkRow(int i,pii res,int l,int r,int p)
{
if(res.fi!=-1)
{
if(tag[p]<=2)
{
reset(p);
for(int x:s[p])upd(res,x);
}
else res=pii(-1,-1);
}
if(l==r){a[i][l]=res;return;}
dmid;mkRow(i,res,lson),mkRow(i,res,rson);
}
inline void build(int l,int r,int p)
{
tag[p]=0;vector<int>().swap(s[p]);
if(l==r)return;dmid;build(lson),build(rson);
}
};
Seg t;
inline void work()
{
n=rd(),m=rd(),w=0;cnt=0,Ans=0;
for(int i=0;i<=m+1;i++)vector<P>().swap(A[i]),vector<P>().swap(B[i]);
t.build(root);
for(int i=1;i<=n;i++)
{
map<int,int>().swap(s[i]);
int x0=rd(),x1=rd(),y0=rd(),y1=rd();Sum[i]=0;
A[x0]+=(P){y0,y1,i};B[x1+1]+=(P){y0,y1,i};
}
t.build(root);
for(int i=1;i<=m;i++)
{
for(P p:A[i])t.ins(p.l,p.r,p.v,root);
for(P p:B[i])t.del(p.l,p.r,p.v,root);
t.mkRow(i,pii(0,0),root);
}
for(P p:B[m+1])t.del(p.l,p.r,p.v,root);
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)
{
if(a[i][j].fi>a[i][j].se)swap(a[i][j].fi,a[i][j].se);
if(a[i][j].se==0)cnt++;
else if(a[i][j].fi==0)Sum[a[i][j].se]++;
}
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)
if(a[i][j].fi>0)
{
int x=a[i][j].fi,y=a[i][j].se;
Max(Ans,Sum[x]+Sum[y]+(++s[x][y]));
}
sort(Sum+1,Sum+n+1);
Max(Ans,Sum[n]+Sum[n-1]);
printf("%d\n",m*m-cnt-Ans);
}
int main()
{
for(int test=rd();test;test--)work();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 171468kb
input:
1 4 5 1 1 3 3 2 2 4 4 3 3 5 5 2 3 1 4
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 370ms
memory: 181016kb
input:
1000 10 10 1 7 3 5 2 4 3 6 3 9 8 8 8 9 2 9 3 8 2 10 2 8 1 3 8 9 1 7 2 10 5 10 8 9 3 8 1 3 3 8 10 10 4 9 2 3 2 10 7 8 6 8 8 8 3 10 8 10 6 9 3 9 4 10 3 9 2 4 1 3 1 8 3 9 2 9 8 10 4 10 2 10 10 10 1 1 2 3 7 10 1 4 4 10 1 7 6 6 7 10 3 7 1 5 1 8 8 10 6 9 6 6 4 5 6 9 1 3 4 10 7 7 2 8 10 10 4 7 3 5 2 2 4 4 ...
output:
65 71 64 44 54 37 60 53 42 45 63 61 48 42 47 48 52 64 56 53 39 49 65 33 52 48 70 62 54 49 58 34 52 38 62 51 75 54 31 45 63 54 47 56 61 50 28 62 54 53 66 64 52 44 50 46 41 48 34 28 56 57 54 26 61 46 48 55 50 43 78 41 58 53 54 51 56 37 33 48 52 59 58 55 55 61 56 58 61 71 56 40 44 36 42 45 58 30 44 63 ...
result:
ok 1000 lines
Test #3:
score: 0
Accepted
time: 1164ms
memory: 213652kb
input:
7 300000 1500 21 1482 660 831 992 1055 675 868 1021 1375 335 654 880 1358 582 1476 1085 1174 60 1047 702 907 274 421 64 1113 1267 1431 213 1236 748 875 27 243 933 1303 1092 1385 103 893 388 1173 817 1126 254 515 509 1175 104 621 459 565 74 813 402 539 189 927 821 918 189 1264 1307 1460 137 1426 1392...
output:
2249982 2249981 2249991 2249984 2249980 2249977 2249954
result:
ok 7 lines
Test #4:
score: 0
Accepted
time: 950ms
memory: 213004kb
input:
7 300000 1500 1 2 1 2 1 2 2 3 1 2 3 4 1 2 4 5 1 2 5 6 1 2 6 7 1 2 7 8 1 2 8 9 1 2 9 10 1 2 10 11 1 2 11 12 1 2 12 13 1 2 13 14 1 2 14 15 1 2 15 16 1 2 16 17 1 2 17 18 1 2 18 19 1 2 19 20 1 2 20 21 1 2 21 22 1 2 22 23 1 2 23 24 1 2 24 25 1 2 25 26 1 2 26 27 1 2 27 28 1 2 28 29 1 2 29 30 1 2 30 31 1 2...
output:
600398 900597 1200796 1500995 1801194 2101393 600396
result:
ok 7 lines
Test #5:
score: 0
Accepted
time: 1239ms
memory: 205424kb
input:
8 250000 1500 1 4 1 4 2 3 2 4 1 4 5 8 3 3 5 5 1 4 9 12 2 3 10 11 1 4 13 16 3 4 16 16 1 4 17 20 1 4 19 20 1 4 21 24 2 3 22 24 1 4 25 28 2 2 27 27 1 4 29 32 1 3 30 32 1 4 33 36 3 4 34 36 1 4 37 40 1 1 39 39 1 4 41 44 3 4 42 42 1 4 45 48 1 2 47 48 1 4 49 52 2 2 50 52 1 4 53 56 1 3 54 56 1 4 57 60 2 2 5...
output:
1999970 1999970 1999970 1999970 1999970 1999970 1999970 1999970
result:
ok 8 lines
Test #6:
score: 0
Accepted
time: 882ms
memory: 199308kb
input:
20 100000 1500 27 1471 30 1477 6 1465 17 1470 26 1468 35 1483 25 1472 21 1455 43 1474 18 1480 23 1462 7 1476 41 1485 47 1488 27 1472 9 1478 26 1495 27 1475 20 1472 35 1457 43 1477 22 1482 31 1452 42 1457 25 1462 38 1468 5 1476 16 1489 34 1483 32 1491 13 1461 25 1494 22 1464 45 1465 32 1481 29 1453 3...
output:
2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081 2223081
result:
ok 20 lines