QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#717126 | #9465. 基础 01 练习题 | Mathew_Miao | 5 | 245ms | 40236kb | C++23 | 2.8kb | 2024-11-06 16:59:48 | 2024-11-06 16:59:48 |
Judging History
answer
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<string>
#include<bitset>
#include<numeric>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=5e3+10;
const int N=5e3;
const int INF=0x3f3f3f3f;
const long long LINF=0x3f3f3f3f3f3f3f3f;
int n,q,op;
string s[MAXN];
#define pii pair<int,int>
basic_string <pii> row[MAXN],col[MAXN];
int rnk[MAXN];
inline bool cmp(int x,int y){
return s[x]>s[y];
}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/priority_queue.hpp>
namespace ODT{
long long res=0;
int val[MAXN];
__gnu_pbds::priority_queue <int,greater<int>> tag[MAXN];
set <pii> s;
#define IT set<pii>::iterator
inline void assign(int l,int r){
IT itl=prev(s.lower_bound(pii(l+1,0))),itr=prev(s.lower_bound(pii(r+1,0)));
l=itl->first;
r=itr->second;
int sum=1;
for(IT it=itl;it!=next(itr);it++)
{
auto [tl,tr]=*it;
if(l^tl){
tag[l].join(tag[tl]);
}
res-=max((tr-tl+1ll)*val[tl]-1,0ll);
sum+=val[tl];
}
s.erase(itl,next(itr));
val[l]=sum;
while(!tag[l].empty()&&l<=tag[l].top())
{
val[l]++;
tag[l].pop();
}
res+=max((r-l+1ll)*val[l]-1,0ll);
s.insert(pii(l,r));
}
inline void modify(int l,int r){
IT it=prev(s.lower_bound(pii(r+1,0)));
if(it->first<=l){
res-=max((it->second-it->first+1ll)*val[it->first]-1,0ll);
val[it->first]++;
res+=max((it->second-it->first+1ll)*val[it->first]-1,0ll);
}
else{
tag[it->first].push(l);
}
}
inline void build(){
for(int i=1;i<=n;i++)
{
s.insert(pii(i,i));
}
}
}
inline void solve(){
scanf("%d%d%d",&n,&q,&op);
while(q--)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
row[x1].push_back(pii(y1,y2));
row[x2+1].push_back(pii(y1,y2));
col[y1].push_back(pii(x1,x2));
col[y2+1].push_back(pii(x1,x2));
}
s[0]=' '+string(n,'0');
for(int i=1;i<=n;i++)
{
s[i]=s[i-1];
for(auto [l,r]:row[i])
{
for_each(s[i].begin()+l,s[i].begin()+r+1,[&](char& c){c^=1;});
}
}
iota(rnk+1,rnk+1+n,1);
sort(rnk+1,rnk+1+n,cmp);
ODT::build();
for(int i=1;i<=n;i++)
{
int l=n+1,r=0;
for(int j=1;j<=n;j++)
{
if(s[rnk[j]][i]=='0'){
l=j;
break;
}
}
for(int j=n;j;j--)
{
if(s[rnk[j]][i]=='1'){
r=j;
break;
}
}
if(l<=r){
ODT::assign(l,r);
}
else{
ODT::modify(r,l);
}
if(op){
printf("%lld ",1ll*n*i-ODT::res);
}
}
if(!op){
printf("%lld",1ll*n*n-ODT::res);
}
putchar('\n');
}
signed main(){
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
atexit([](){fprintf(stderr,"%.3lfs\n",(double)clock()/CLOCKS_PER_SEC);});
#endif
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 4396kb
input:
4 1000 0 2 3 1 2 1 3 1 3 1 2 1 2 1 2 3 4 1 4 2 4 1 3 1 2 1 4 1 2 1 3 1 4 3 3 2 3 1 2 2 4 4 4 1 3 3 3 3 4 3 4 3 4 2 3 1 1 1 2 2 4 1 4 3 4 3 4 1 2 1 2 2 3 3 4 3 3 1 2 4 4 4 4 2 4 1 4 1 1 1 1 1 3 2 3 2 3 1 1 2 4 2 3 2 4 3 3 1 4 3 3 3 3 1 3 3 3 2 3 2 4 3 3 2 2 1 3 2 4 1 3 1 2 3 4 1 2 2 3 1 3 1 1 1 2 1 2...
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 5
Accepted
time: 0ms
memory: 4444kb
input:
4 1000 0 1 4 3 3 2 3 4 4 3 4 3 4 3 4 1 2 1 4 2 4 2 3 1 3 3 4 2 4 2 3 3 3 3 4 1 3 1 3 1 4 2 3 1 3 1 1 2 2 1 4 3 4 1 4 1 3 1 2 3 4 1 2 1 2 2 3 1 4 2 2 2 2 1 3 1 3 2 2 2 4 1 2 1 4 1 1 1 1 1 2 3 4 4 4 1 3 2 4 1 3 1 1 1 3 1 4 2 2 2 3 1 2 2 2 1 2 1 2 1 4 1 4 2 4 1 2 1 3 1 2 1 3 2 4 2 2 1 2 1 1 1 2 1 3 2 4...
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 5
Accepted
time: 1ms
memory: 4444kb
input:
4 1000 0 1 4 1 2 1 4 2 2 1 4 3 4 2 4 4 4 2 3 3 4 2 4 2 4 1 2 2 2 4 4 2 4 1 3 1 3 1 4 1 4 3 3 3 4 4 4 2 3 2 3 1 4 2 2 1 3 2 3 2 4 2 2 1 4 1 2 2 3 1 4 1 3 4 4 1 4 3 4 1 4 1 2 1 2 1 2 1 3 2 2 3 3 1 2 1 4 1 1 1 4 2 2 1 4 1 4 3 4 2 4 2 4 2 2 1 4 3 4 1 3 2 3 2 4 1 3 1 4 1 3 1 4 3 3 1 3 1 2 1 3 3 3 1 4 1 4...
output:
5
result:
ok 1 number(s): "5"
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 10
Accepted
time: 37ms
memory: 11452kb
input:
50 200000 0 1 45 2 6 29 44 2 6 31 37 2 50 2 37 1 19 7 13 8 38 38 46 19 38 10 30 30 46 22 42 1 45 5 35 24 27 10 36 19 31 20 47 17 35 7 9 23 42 15 26 31 42 7 8 7 42 1 26 33 48 2 5 30 36 17 44 21 44 5 44 24 36 19 47 15 17 29 36 2 42 31 34 11 41 9 24 12 30 30 43 8 20 2 12 13 20 11 12 10 15 14 22 3 29 2 ...
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 4472kb
input:
50 70 0 1 50 1 50 24 50 1 1 50 50 2 2 34 50 3 3 36 50 4 4 32 50 5 5 18 50 6 6 12 50 7 7 6 50 8 8 28 50 9 9 38 50 10 10 4 50 11 11 26 50 12 12 14 50 13 13 46 50 14 14 2 50 15 15 8 50 16 16 44 50 17 17 10 50 18 18 30 50 19 19 22 50 20 20 48 50 21 21 20 50 22 22 42 50 23 23 40 50 24 24 16 50 25 25 16 5...
output:
2285
result:
wrong answer 1st numbers differ - expected: '2280', found: '2285'
Subtask #3:
score: 0
Wrong Answer
Test #8:
score: 10
Accepted
time: 230ms
memory: 39936kb
input:
5000 200000 0 1438 2561 3478 4930 1740 4634 87 3003 590 3275 1376 1681 2035 2793 2004 4945 567 3159 550 4470 61 3039 3431 3519 2654 3834 3460 4960 591 3560 409 443 345 2599 746 2891 1288 4570 1577 4402 249 377 1951 4534 2411 2455 294 1192 1679 3153 1645 4259 1735 1856 601 668 477 4881 411 2094 424 1...
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 10
Accepted
time: 202ms
memory: 36376kb
input:
5000 200000 0 4336 5000 1 1 686 5000 2 2 3130 5000 3 3 672 5000 4 4 1664 5000 5 5 1480 5000 6 6 1326 5000 7 7 3726 5000 8 8 4170 5000 9 9 4794 5000 10 10 3374 5000 11 11 1836 5000 12 12 310 5000 13 13 2146 5000 14 14 3266 5000 15 15 820 5000 16 16 1152 5000 17 17 2876 5000 18 18 134 5000 19 19 828 5...
output:
24995
result:
ok 1 number(s): "24995"
Test #10:
score: 10
Accepted
time: 203ms
memory: 36492kb
input:
5000 200000 0 1410 5000 1 1 3340 5000 2 2 4202 5000 3 3 4450 5000 4 4 914 5000 5 5 4514 5000 6 6 4 5000 7 7 238 5000 8 8 3182 5000 9 9 3302 5000 10 10 2136 5000 11 11 1504 5000 12 12 3204 5000 13 13 2078 5000 14 14 4026 5000 15 15 3690 5000 16 16 4430 5000 17 17 1304 5000 18 18 2156 5000 19 19 4154 ...
output:
10000
result:
ok 1 number(s): "10000"
Test #11:
score: 10
Accepted
time: 191ms
memory: 37304kb
input:
5000 200000 0 1556 3445 1 1 1803 3198 2 2 790 4211 3 3 564 4437 4 4 1128 3873 5 5 129 4872 6 6 2062 2939 7 7 1480 3521 8 8 1252 3749 9 9 942 4059 10 10 111 4890 11 11 915 4086 12 12 1575 3426 13 13 2186 2815 14 14 392 4609 15 15 1689 3312 16 16 492 4509 17 17 866 4135 18 18 381 4620 19 19 92 4909 20...
output:
34989
result:
ok 1 number(s): "34989"
Test #12:
score: 0
Wrong Answer
time: 223ms
memory: 37188kb
input:
5000 200000 0 1 1 2330 2671 2 2 789 4212 3 3 1593 3408 4 4 438 4563 5 5 2048 2953 6 6 491 4510 7 7 578 4423 8 8 770 4231 9 9 482 4519 10 10 395 4606 11 11 1960 3041 12 12 1289 3712 13 13 621 4380 14 14 2235 2766 15 15 916 4085 16 16 781 4220 17 17 1440 3561 18 18 902 4099 19 19 1998 3003 20 20 641 4...
output:
54972
result:
wrong answer 1st numbers differ - expected: '49977', found: '54972'
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 10
Accepted
time: 230ms
memory: 40236kb
input:
5000 200000 1 565 4401 1659 1826 429 1640 2999 3495 572 3994 9 3863 3844 4284 2307 3144 1054 1943 358 2592 727 4248 29 1171 1685 2392 4559 4929 1149 2787 1204 1947 2349 2619 405 998 1910 2786 25 1275 912 3475 4384 4387 3822 4895 1849 4548 3082 4749 3457 4220 3174 4885 117 1085 2517 3919 4325 4869 17...
output:
5000 5653 3715 1781 1031 823 540 185 190 71 56 61 66 71 76 81 86 91 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
result:
ok 5000 numbers
Test #15:
score: 0
Wrong Answer
time: 245ms
memory: 36284kb
input:
5000 200000 1 1 1 4840 5000 2 2 1690 5000 3 3 908 5000 4 4 1212 5000 5 5 2712 5000 6 6 3950 5000 7 7 4724 5000 8 8 3706 5000 9 9 1888 5000 10 10 4056 5000 11 11 1074 5000 12 12 3806 5000 13 13 3756 5000 14 14 2822 5000 15 15 1264 5000 16 16 4088 5000 17 17 796 5000 18 18 4888 5000 19 19 4610 5000 20...
output:
5000 9997 14997 19997 24997 29996 34974 39958 44944 49928 54902 59872 64858 69833 74833 79777 84760 89728 94710 99675 104675 109599 114578 119536 124492 129423 134374 139298 144270 149188 154130 159041 163948 168851 173814 178678 183638 188563 193522 198522 203288 208204 213158 218030 222898 227719 ...
result:
wrong answer 6th numbers differ - expected: '29994', found: '29996'
Subtask #5:
score: 0
Runtime Error
Test #21:
score: 0
Runtime Error
input:
200000 200000 1 1 2 1 6 3 4 1 1 5 6 1 5 7 8 1 3 9 10 1 3 11 12 1 6 13 14 1 5 15 16 1 6 17 18 1 6 19 20 1 1 21 22 1 4 23 24 1 5 25 26 1 2 27 28 1 4 29 30 1 3 31 32 1 2 33 34 1 6 35 36 1 3 37 38 1 2 39 40 1 2 41 42 1 3 43 44 1 1 45 46 1 2 47 48 1 3 49 50 1 4 51 52 1 5 53 54 1 1 55 56 1 5 57 58 1 5 59 ...
output:
result:
Subtask #6:
score: 0
Runtime Error
Test #28:
score: 0
Runtime Error
input:
200000 200000 0 91264 123676 6826 154505 121351 188051 108158 131448 65413 163961 26771 116304 93852 110556 34929 187363 31794 142162 33578 38712 26574 67763 178013 197235 46436 146042 95 122860 11683 50463 60177 195245 60862 194711 37817 97212 144366 176271 113551 171098 120095 170517 73555 167299 ...
output:
result:
Subtask #7:
score: 0
Runtime Error
Test #37:
score: 0
Runtime Error
input:
100000 200000 1 1 22878 1 2 1 7957 3 4 1 21779 5 6 1 34321 7 8 1 41692 9 10 1 49473 11 12 1 10254 13 14 1 43995 15 16 1 46975 17 18 1 668 19 20 1 25996 21 22 1 24975 23 24 1 43259 25 26 1 4174 27 28 1 39330 29 30 1 35462 31 32 1 27523 33 34 1 5574 35 36 1 47955 37 38 1 47013 39 40 1 3846 41 42 1 276...