QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#185218 | #7182. Very Sparse Table | ucup-team1004 | AC ✓ | 441ms | 33892kb | C++14 | 3.0kb | 2023-09-21 19:12:56 | 2023-09-21 19:12:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=1<<16|10;
int n,nn,a[N],b[N],is[N];
vector<tuple<int,int,int> >ans;
void add(int x,int y,int z){
ans.push_back({x,y,z});
}
int l[N],r[N],pre[N],nex[N],vis[N];
void link2(int s,int t){
int x=s+5,y=t-6;
vis[x]=vis[y]=1;
for(int i=x;i<t;i++){
pre[i]=vis[i]?i:pre[i-1];
if(pre[i]<i-1)add(pre[i],i-1,i);
}
for(int i=y;i>s;i--){
nex[i]=vis[i]?i:nex[i+1];
if(nex[i]>i+1)add(i,i+1,nex[i]);
}
add(x,y-1,y),add(y+1,y+2,y+3);
}
void link1(int s,int t){
int B=16;
for(int i=s;i<=t;i++){
l[i]=i%B?l[i-1]:i;
}
for(int i=t;i>=s;i--){
r[i]=i%B?r[i+1]:i;
}
for(int i=s;i<=t;i++){
if(l[i]<i-1)add(l[i],i-1,i);
}
for(int i=t;i>=s;i--){
if(r[i]>i+1)add(i,i+1,r[i]);
}
vector<int>p;
for(int i=s;i<=t;i+=B){
p.push_back(i);
}
int len=p.size();
for(int i=1;i<len;i++)add(p[i-1],p[i]-1,p[i]);
for(int d=2;d<len;d++){
for(int i=d;i<len;i++){
add(p[i-d],p[i-1],p[i]);
}
}
for(int i=1;i<len;i++)link2(p[i-1],p[i]);
}
void print(vector<int>x){
for(int len=x.size(),i=0;i<len;i++){
if(!i||x[i]^x[i-1])printf("%d ",x[i]);
}
puts(""),fflush(stdout);
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
memset(b,-1,sizeof b);
memset(r,-1,sizeof r);
memset(nex,-1,sizeof nex);
scanf("%d",&n),nn=n,n=1<<16;
int B=256;
for(int i=0;i<=n;i++){
is[i]=i%B==0;
}
for(int i=0;i<=n;i++){
a[i]=is[i]?i:a[i-1];
}
for(int i=n;i>=0;i--){
b[i]=is[i]?i:b[i+1];
}
for(int i=0;i<=n;i++){
if(a[i]<i-1)add(a[i],i-1,i);
}
for(int i=n;i>=0;i--){
if(b[i]>i+1)add(i,i+1,b[i]);
}
vector<int>t;
for(int i=0;i<=n;i++)if(is[i])t.push_back(i);
int len=t.size();
for(int i=1;i<len;i++)add(t[i-1],t[i]-1,t[i]);
for(int d=2;d<len;d++){
for(int i=d;i<len;i++){
add(t[i-d],t[i-1],t[i]);
}
}
for(int i=1;i<len;i++)link1(t[i-1],t[i]);
vector<tuple<int,int,int> >res;
set<pair<int,int> >s;
for(auto t:ans){
int x,y,z;
tie(x,y,z)=t;
if(z<=nn&&!s.count({x,z})){
res.push_back({x,y,z}),s.insert({x,z});
}
}
printf("%d\n",(int)res.size());
for(auto t:res){
int x,y,z;
tie(x,y,z)=t;
printf("%d %d %d\n",x,y,z);
}
fflush(stdout);
int q;
scanf("%d",&q);
for(int x,y;q--;){
scanf("%d%d",&x,&y);
if(~b[x]&&b[x]<=a[y])print({x,b[x],a[y],y});
else if(~r[x]&&r[x]<=l[y])print({x,r[x],l[y],y});
else if(~nex[x]&&nex[x]<=pre[y])print({x,nex[x],pre[y],y});
else if(y-x>3)print({x,x+2,y-1,y});
else{
for(int i=x;i<=y;i++)printf("%d ",i);
puts("");
}
fflush(stdout);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13076kb
input:
9 45 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 4 3 5 3 6 3 7 3 8 3 9 4 5 4 6 4 7 4 8 4 9 5 6 5 7 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9
output:
14 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 5 6 7 5 7 8 5 8 9 3 4 5 2 3 5 1 2 5 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 2 1 2 3 1 2 3 4 1 5 1 5 6 1 5 7 1 5 8 1 5 9 2 3 2 3 4 2 5 2 5 6 2 5 7 2 5 8 2 5 9 3 4 3 5 3 5 6 3 5 7 3 5 8 3 5 9 4 5 4 5 6 4 5 7 4 5 8 4 5 9...
result:
ok edges: 14
Test #2:
score: 0
Accepted
time: 0ms
memory: 11180kb
input:
30 465 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0 16 0 17 0 18 0 19 0 20 0 21 0 22 0 23 0 24 0 25 0 26 0 27 0 28 0 29 0 30 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 2 3 2 4 2 5 2 6...
output:
85 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 0 19 20 0 20 21 0 21 22 0 22 23 0 23 24 0 24 25 0 25 26 0 26 27 0 27 28 0 28 29 0 29 30 16 17 18 16 18 19 16 19 20 16 20 21 16 21 22 16 22 23 16 23 24 16 24 25 16 25 26 1...
result:
ok edges: 85
Test #3:
score: 0
Accepted
time: 182ms
memory: 13176kb
input:
736 200000 170 268 126 166 565 723 664 735 61 524 226 234 146 314 217 272 294 713 115 381 563 706 74 567 552 614 120 211 472 620 213 432 488 623 447 564 96 129 331 354 79 677 50 547 174 568 56 129 189 227 55 701 244 253 264 715 154 220 380 657 46 390 53 161 325 537 666 696 64 465 391 659 284 448 207...
output:
3451 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 0 19 20 0 20 21 0 21 22 0 22 23 0 23 24 0 24 25 0 25 26 0 26 27 0 27 28 0 28 29 0 29 30 0 30 31 0 31 32 0 32 33 0 33 34 0 34 35 0 35 36 0 36 37 0 37 38 0 38 39 0 39 40 ...
result:
ok edges: 3451
Test #4:
score: 0
Accepted
time: 348ms
memory: 31628kb
input:
65536 200000 51949 58727 7943 43298 6290 7369 41493 53070 24229 36675 28087 49947 11703 48217 19923 24739 2144 59777 53830 56793 13509 37211 2300 38595 27415 42879 24616 48531 58341 63327 20628 38407 48616 60290 7450 61685 37010 47595 22164 42732 19181 29850 35383 43587 39257 44397 19340 45183 34523...
output:
358784 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 0 19 20 0 20 21 0 21 22 0 22 23 0 23 24 0 24 25 0 25 26 0 26 27 0 27 28 0 28 29 0 29 30 0 30 31 0 31 32 0 32 33 0 33 34 0 34 35 0 35 36 0 36 37 0 37 38 0 38 39 0 39 4...
result:
ok edges: 358784
Test #5:
score: 0
Accepted
time: 0ms
memory: 12648kb
input:
0 0
output:
0
result:
ok edges: 0
Test #6:
score: 0
Accepted
time: 6ms
memory: 12460kb
input:
1 1 0 1
output:
0 0 1
result:
ok edges: 0
Test #7:
score: 0
Accepted
time: 5ms
memory: 12180kb
input:
2 3 0 1 0 2 1 2
output:
1 0 1 2 0 1 0 2 1 2
result:
ok edges: 1
Test #8:
score: 0
Accepted
time: 0ms
memory: 11812kb
input:
3 6 0 1 0 2 0 3 1 2 1 3 2 3
output:
2 0 1 2 0 2 3 0 1 0 2 0 3 1 2 1 2 3 2 3
result:
ok edges: 2
Test #9:
score: 0
Accepted
time: 370ms
memory: 30588kb
input:
65535 200000 35006 46944 17075 57351 24605 50445 5938 60705 15221 40233 28599 38915 1132 35574 8555 31494 13644 35806 44940 55401 9503 59206 21011 26540 41156 62487 57510 64305 9254 25610 17301 47249 34083 49167 48018 64394 38855 62175 15464 22525 23728 60275 54028 63810 22711 53902 5984 48625 5838 ...
output:
358274 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 0 19 20 0 20 21 0 21 22 0 22 23 0 23 24 0 24 25 0 25 26 0 26 27 0 27 28 0 28 29 0 29 30 0 30 31 0 31 32 0 32 33 0 33 34 0 34 35 0 35 36 0 36 37 0 37 38 0 38 39 0 39 4...
result:
ok edges: 358274
Test #10:
score: 0
Accepted
time: 441ms
memory: 33892kb
input:
64800 200000 55124 62263 24992 39760 32262 37059 25987 42889 10413 64701 7223 43221 45810 63205 11437 29357 10814 52096 1154 36319 10730 54157 18473 26729 9152 23374 5426 12744 3502 37577 5559 37160 30503 62433 12426 47332 14933 62086 8781 21527 27180 53773 29658 46742 20592 61553 8337 27197 8024 38...
output:
354304 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10 11 0 11 12 0 12 13 0 13 14 0 14 15 0 15 16 0 16 17 0 17 18 0 18 19 0 19 20 0 20 21 0 21 22 0 22 23 0 23 24 0 24 25 0 25 26 0 26 27 0 27 28 0 28 29 0 29 30 0 30 31 0 31 32 0 32 33 0 33 34 0 34 35 0 35 36 0 36 37 0 37 38 0 38 39 0 39 4...
result:
ok edges: 354304
Extra Test:
score: 0
Extra Test Passed