QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368071 | #3918. Permutations again | KLPP# | WA | 204ms | 148372kb | C++20 | 2.1kb | 2024-03-26 19:40:30 | 2024-03-26 19:40:31 |
Judging History
answer
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
bool in[2000000];
int arr[2000000];
const int MAX=1e6;
vector<pair<int,int> >Q;
class ST{
pair<lld,int> M[4*MAX];
public:
void build(int a, int b, int node){
if(a==b){
M[node]={arr[a],a};
return;
}
int mid=(a+b)/2;
build(a,mid,2*node);
build(mid+1,b,2*node+1);
M[node]=max(M[2*node],M[2*node+1]);
}
pair<lld,int> query(int a, int b, int node, int l, int r){
if(r<a || b<l)return {-1,-1};
if(l<=a && b<=r)return M[node];
int mid=(a+b)/2;
return max(query(a,mid,2*node,l,r),query(mid+1,b,2*node+1,l,r));
}
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using ui64 = unsigned long long;
ui64 gerar(ui64 lo, ui64 hi) { return uniform_int_distribution<ui64>(lo,hi)(rng); }
using namespace chrono;
ST S;
int n;
void process(int a, int b){
if(a>b)return;
pair<lld,int> p=S.query(0,n-1,1,a,b);
int pos=p.second;
int val=p.first;
rep(i,max(a,pos+1-val),min(b,pos)+1){
if(i+val-1>b)break;
Q.push_back({i,i+val-1});
}
process(a,pos-1);
process(pos+1,b);
}
vector<bool> W;
lld hsh[1000000];
lld pref[1000000];
lld tar[1000000];
void Tr(){
rep(i,0,n){
hsh[i]=gerar(0,1e9);
}
pref[0]=0;
rep(i,0,n){
pref[i+1]=pref[i]+hsh[arr[i]-1];
}
tar[0]=0;
rep(i,0,n){
tar[i+1]=tar[i]+hsh[i];
}
rep(i,0,(int)Q.size()){
int l=Q[i].first;
int r=Q[i].second;
if(tar[r-l+1]!=pref[r+1]-pref[l]){
W[i]=false;
}
}
}
void solve(){
cin>>n;
rep(i,0,n){
cin>>arr[i];
}
S.build(0,n-1,1);
process(0,n-1);
W.resize(Q.size(),true);
rep(t,0,4){
Tr();
}
lld ans=0;
trav(a,W)ans+=a;
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
//cin>>tt;
while(tt--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 11880kb
input:
3 3 1 2
output:
3
result:
ok answer is '3'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11880kb
input:
1 1
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 11916kb
input:
2 2 2
output:
0
result:
ok answer is '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 11916kb
input:
2 1 1
output:
2
result:
ok answer is '2'
Test #5:
score: 0
Accepted
time: 1ms
memory: 11844kb
input:
8 4 3 2 1 3 2 4 1
output:
9
result:
ok answer is '9'
Test #6:
score: 0
Accepted
time: 1ms
memory: 11824kb
input:
7 3 2 1 3 2 1 2
output:
9
result:
ok answer is '9'
Test #7:
score: 0
Accepted
time: 0ms
memory: 11908kb
input:
9 2 1 3 2 1 4 2 3 1
output:
12
result:
ok answer is '12'
Test #8:
score: 0
Accepted
time: 0ms
memory: 11912kb
input:
5 3 2 1 4 3
output:
5
result:
ok answer is '5'
Test #9:
score: 0
Accepted
time: 0ms
memory: 11908kb
input:
5 5 2 3 1 4
output:
4
result:
ok answer is '4'
Test #10:
score: 0
Accepted
time: 1ms
memory: 11912kb
input:
2 2 1
output:
2
result:
ok answer is '2'
Test #11:
score: 0
Accepted
time: 1ms
memory: 11912kb
input:
10 10 9 8 7 6 5 4 3 2 1
output:
10
result:
ok answer is '10'
Test #12:
score: 0
Accepted
time: 1ms
memory: 11904kb
input:
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 64 63 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1 2 3 4...
output:
1184
result:
ok answer is '1184'
Test #13:
score: 0
Accepted
time: 1ms
memory: 11872kb
input:
2000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 29 19 20 21 22 23 24 25 26 27 28 18 1 2 3 4 5 22 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 6 23 24 25 26 27 28 29 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 23 22 24 25 26 27 28 29 1 2 3 27 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
output:
2359
result:
ok answer is '2359'
Test #14:
score: 0
Accepted
time: 1ms
memory: 11972kb
input:
3000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 29 25 26 27 28 24 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 1 2 3 4 5 43 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 6 44 45 46 47 48 49 1 2 3 4 5 6 7 8 9 1...
output:
3207
result:
ok answer is '3207'
Test #15:
score: 0
Accepted
time: 20ms
memory: 23524kb
input:
98947 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 107 98 99 100 1...
output:
108492
result:
ok answer is '108492'
Test #16:
score: 0
Accepted
time: 12ms
memory: 17444kb
input:
83887 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 822 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
102604
result:
ok answer is '102604'
Test #17:
score: 0
Accepted
time: 16ms
memory: 22980kb
input:
80773 1 2 3 4 9 6 7 8 5 1 2 3 4 9 6 7 8 5 5 2 3 4 1 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 5 4 3 6 7 8 9 1 2 6 4 5 3 7 8 9 1 2 3 4 5 6 7 8 9 1 8 3 4 5 6 7 2 9 1 3 2 4 5 6 7 8 9 1 2 3 5 4 6 7 8 9 1 2 3 4 8 6 7 5 9 5 2 3 4 1 6 7 8 9 1 2 3 4 9 6 7 8 5 1 2 3 4 5 6 7 8 9 1 2 3 8 5 6 7 4 9 1 8 3 4 5 6 7 2 9 1 2 3 ...
output:
89642
result:
ok answer is '89642'
Test #18:
score: 0
Accepted
time: 10ms
memory: 22164kb
input:
81060 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
107523
result:
ok answer is '107523'
Test #19:
score: 0
Accepted
time: 1ms
memory: 11988kb
input:
2034 8 13 25 12 1 15 10 18 11 29 28 6 19 5 20 16 24 17 14 21 9 7 22 27 23 3 4 2 26 14 8 9 18 13 28 24 29 3 10 6 22 4 11 19 1 15 17 5 16 12 7 21 27 20 2 25 26 23 3 18 13 24 14 29 22 12 25 20 8 16 5 28 27 15 7 10 17 6 23 19 4 2 26 21 1 9 11 21 7 16 8 19 17 24 11 27 20 23 2 28 18 4 26 10 1 6 9 13 12 14...
output:
155
result:
ok answer is '155'
Test #20:
score: 0
Accepted
time: 0ms
memory: 11932kb
input:
2576 49 12 14 28 30 44 11 29 31 6 9 25 35 33 39 7 27 46 26 22 36 45 1 10 3 17 38 37 2 34 48 47 18 40 5 8 20 19 32 23 42 24 13 41 16 43 15 21 4 21 15 17 28 13 1 9 12 24 45 31 14 47 30 20 29 36 6 8 7 16 34 32 4 37 27 40 42 33 26 22 38 2 35 11 48 49 23 46 3 39 5 44 19 10 41 18 43 25 37 15 10 12 20 18 7...
output:
113
result:
ok answer is '113'
Test #21:
score: 0
Accepted
time: 10ms
memory: 19200kb
input:
91547 430 206 395 465 267 173 207 4 361 472 457 389 161 221 388 119 493 447 289 235 240 298 184 203 224 286 274 145 365 262 282 219 488 74 372 196 172 157 287 476 418 357 237 232 334 114 366 320 350 308 227 492 150 200 257 57 416 359 265 332 181 55 230 96 450 293 175 69 315 329 58 211 128 316 231 40...
output:
369
result:
ok answer is '369'
Test #22:
score: 0
Accepted
time: 7ms
memory: 19140kb
input:
96540 81 731 673 853 78 984 690 146 764 286 83 949 105 70 852 337 320 253 110 460 32 865 52 726 613 261 450 125 160 659 377 420 630 560 628 303 193 750 94 170 195 476 955 578 942 904 561 62 746 969 364 91 451 481 825 712 63 408 25 936 399 443 117 257 944 194 533 478 130 221 225 903 986 549 550 482 5...
output:
195
result:
ok answer is '195'
Test #23:
score: 0
Accepted
time: 19ms
memory: 20944kb
input:
95611 2 9 6 8 5 7 3 4 1 5 9 2 4 1 6 8 3 7 4 5 1 6 2 8 7 3 9 4 1 3 6 5 2 7 8 9 1 8 6 4 7 2 3 9 5 6 7 1 4 8 2 3 5 9 1 3 7 8 4 9 2 5 6 2 9 5 6 4 7 8 1 3 2 5 4 8 1 3 6 7 9 3 4 2 7 1 6 8 9 5 9 5 6 8 4 2 7 3 1 6 5 2 3 4 1 8 7 9 9 8 5 6 4 3 1 7 2 8 4 2 7 6 3 1 5 9 9 5 4 1 6 3 7 2 8 8 4 7 5 6 2 3 9 1 1 3 5 ...
output:
34779
result:
ok answer is '34779'
Test #24:
score: 0
Accepted
time: 16ms
memory: 19116kb
input:
97725 3991 3 1981 19967 11964 15578 16466 22908 26096 13582 2927 5535 23996 18131 27312 8677 21011 5011 10177 1722 9529 21839 22490 11927 4229 15298 22299 15233 7997 13613 5127 5844 27128 27550 12072 24859 4560 25518 2412 21683 2011 4871 10669 5689 18392 15052 19496 12803 14508 1131 21130 4319 14520...
output:
6
result:
ok answer is '6'
Test #25:
score: 0
Accepted
time: 204ms
memory: 148372kb
input:
934066 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
1468132
result:
ok answer is '1468132'
Test #26:
score: 0
Accepted
time: 136ms
memory: 122140kb
input:
959504 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3...
output:
1679129
result:
ok answer is '1679129'
Test #27:
score: 0
Accepted
time: 175ms
memory: 74144kb
input:
906335 34453 21510 58631 37062 98753 171711 90398 8616 136357 132511 175779 95425 191426 92515 195256 196920 35496 148933 65051 48297 14535 197160 62461 106747 20973 189201 43538 132425 138231 114473 14109 109676 88427 194981 24743 189284 134788 124796 138191 120524 4607 61492 127967 113633 1 80151 ...
output:
9023
result:
ok answer is '9023'
Test #28:
score: -100
Wrong Answer
time: 188ms
memory: 112748kb
input:
1000000 1 3 2 2 5 4 3 4 5 1 2 4 1 4 4 5 2 4 2 5 1 5 3 4 1 3 2 3 5 4 2 2 5 4 4 1 1 1 3 3 4 5 2 3 1 2 3 4 1 3 1 5 2 5 5 1 2 3 2 2 5 3 4 4 5 1 3 4 3 5 1 2 4 1 5 1 1 2 4 5 1 4 3 5 4 5 5 4 1 3 4 2 4 3 4 4 3 3 5 2 1 4 3 2 4 1 4 1 4 1 1 4 1 2 2 1 2 5 5 5 2 3 4 4 4 5 4 1 1 1 5 3 1 1 4 1 4 3 1 2 3 3 2 1 4 1 ...
output:
0
result:
wrong answer expected '418855', found '0'