QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#180694 | #7182. Very Sparse Table | do_while_true | AC ✓ | 513ms | 29144kb | C++20 | 3.4kb | 2023-09-16 09:52:35 | 2023-09-16 09:52:36 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<assert.h>
#include<cmath>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=998244353;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
int s=1;
while(y){
if(y&1)s=1ll*s*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return s;
}
#define flh fflush(stdout)
const int N=(1<<16)+10;
int n;
struct edge{
int a,b,c;
edge(int u=0,int v=0,int w=0){a=u,b=v,c=w;}
};
vector<edge>ans;
map<int,int>vis[N];
void adde(int x,int y,int z){
if(vis[x][z])return ;
vis[x][z]=1;
ans.pb(edge(x,y,z));
}
void build(int l,int r){
int len=r-l+1;
int B=sqrt(len);
if(l==r)return ;
if(l+1==r){
adde(l,r,r+1);
return ;
}
vpii vec;
for(int o=1;;o++){
//[(o-1)*B,o*B-1]
if(l+(o-1)*B>r)break;
int L=l+(o-1)*B,R=min(r,l+o*B-1);
build(L,R);
for(int i=L+1;i<=R;i++)
adde(L,i,i+1);
for(int i=R-1;i>=L;i--)
adde(i,i+1,R+1);
vec.pb(mp(L,R));
}
int sz=vec.size();
for(int i=0;i<sz;i++)
for(int j=i+1;j<sz;j++)
adde(vec[i].fi,vec[j].fi,vec[j].se+1);
}
void query(int l,int r,int ql,int qr){
int len=r-l+1;
int B=sqrt(len);
int bl=0,br=0;
for(int o=1;;o++){
//[(o-1)*B,o*B-1]
if(l+(o-1)*B>r)break;
int L=l+(o-1)*B,R=min(r,l+o*B-1);
if(ql>=L&&qr<=R){
query(L,R,ql,qr);
return ;
}
if(ql>=L&&ql<=R)bl=o;
if(qr>=L&&qr<=R)br=o;
}
if(bl+1==br)
if(l+(br-1)*B==qr+1)
cout<<ql<<' '<<qr+1<<'\n';
else
cout<<ql<<' '<<l+(br-1)*B<<' '<<qr+1<<'\n';
else{
if(l+(br-1)*B==qr+1)
cout<<ql<<' '<<l+bl*B<<' '<<qr+1<<'\n';
else
cout<<ql<<' '<<l+bl*B<<' '<<l+(br-1)*B<<' '<<qr+1<<'\n';
}
}
signed main(){
#ifdef do_while_true
assert(freopen("data.in","r",stdin));
// assert(freopen("data.out","w",stdout));
#endif
read(n);
build(0,n-1);
cout<<ans.size()<<'\n';
for(auto i:ans)cout<<i.a<<' '<<i.b<<' '<<i.c<<'\n';
flh;
int q;read(q);
while(q--){
int l,r;read(l,r);
if(l+1==r){
cout<<l<<' '<<r<<'\n';
flh;
continue;
}
query(0,n-1,l,r-1);
flh;
}
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 6588kb
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:
12 0 1 2 0 2 3 1 2 3 3 4 5 3 5 6 4 5 6 6 7 8 6 8 9 7 8 9 0 3 6 0 6 9 3 6 9 0 1 0 1 2 0 1 2 3 0 3 4 0 3 5 0 3 6 0 3 6 7 0 3 6 8 0 3 6 9 1 2 1 2 3 1 3 4 1 3 5 1 3 6 1 3 6 7 1 3 6 8 1 3 6 9 2 3 2 3 4 2 3 5 2 3 6 2 3 6 7 2 3 6 8 2 3 6 9 3 4 3 4 5 3 4 5 6 3 6 7 3 6 8 3 6 9 4 5 4 5 6 4 6 7 4 6 8 4 6 9 5 6...
result:
ok edges: 12
Test #2:
score: 0
Accepted
time: 3ms
memory: 6680kb
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:
63 0 1 2 2 3 4 0 2 4 0 4 5 2 4 5 0 2 3 3 4 5 1 2 5 5 6 7 7 8 9 5 7 9 5 9 10 7 9 10 5 7 8 8 9 10 6 7 10 10 11 12 12 13 14 10 12 14 10 14 15 12 14 15 10 12 13 13 14 15 11 12 15 15 16 17 17 18 19 15 17 19 15 19 20 17 19 20 15 17 18 18 19 20 16 17 20 20 21 22 22 23 24 20 22 24 20 24 25 22 24 25 20 22 23...
result:
ok edges: 63
Test #3:
score: 0
Accepted
time: 282ms
memory: 6984kb
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:
2903 0 1 2 2 3 4 0 2 4 0 4 5 2 4 5 0 2 3 3 4 5 1 2 5 5 6 7 7 8 9 5 7 9 5 9 10 7 9 10 5 7 8 8 9 10 6 7 10 10 11 12 12 13 14 10 12 14 10 14 15 12 14 15 10 12 13 13 14 15 11 12 15 15 16 17 17 18 19 15 17 19 15 19 20 17 19 20 15 17 18 18 19 20 16 17 20 20 21 22 22 23 24 20 22 24 20 24 25 22 24 25 20 22 ...
result:
ok edges: 2903
Test #4:
score: 0
Accepted
time: 483ms
memory: 28448kb
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 2 3 4 0 2 4 0 2 3 1 2 4 4 5 6 6 7 8 4 6 8 4 6 7 5 6 8 8 9 10 10 11 12 8 10 12 8 10 11 9 10 12 12 13 14 14 15 16 12 14 16 12 14 15 13 14 16 0 4 8 0 8 12 0 12 16 4 8 12 4 12 16 8 12 16 0 4 5 0 5 6 0 6 7 0 8 9 0 9 10 0 10 11 0 12 13 0 13 14 0 14 15 11 12 16 10 11 16 9 10 16 7 8 16 6 7 16 5...
result:
ok edges: 358784
Test #5:
score: 0
Accepted
time: 2ms
memory: 6668kb
input:
0 0
output:
0
result:
ok edges: 0
Test #6:
score: 0
Accepted
time: 0ms
memory: 6884kb
input:
1 1 0 1
output:
0 0 1
result:
ok edges: 0
Test #7:
score: 0
Accepted
time: 2ms
memory: 6676kb
input:
2 3 0 1 0 2 1 2
output:
1 0 1 2 0 1 0 1 2 1 2
result:
ok edges: 1
Test #8:
score: 0
Accepted
time: 2ms
memory: 6648kb
input:
3 6 0 1 0 2 0 3 1 2 1 3 2 3
output:
3 0 1 2 0 2 3 1 2 3 0 1 0 1 2 0 1 2 3 1 2 1 2 3 2 3
result:
ok edges: 3
Test #9:
score: 0
Accepted
time: 474ms
memory: 28972kb
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:
362113 0 1 2 0 2 3 1 2 3 3 4 5 3 5 6 4 5 6 6 7 8 6 8 9 7 8 9 9 10 11 9 11 12 10 11 12 12 13 14 12 14 15 13 14 15 0 3 6 0 6 9 0 9 12 0 12 15 3 6 9 3 9 12 3 12 15 6 9 12 6 12 15 9 12 15 0 3 4 0 4 5 0 6 7 0 7 8 0 9 10 0 10 11 0 12 13 0 13 14 11 12 15 10 11 15 8 9 15 7 8 15 5 6 15 4 5 15 2 3 15 1 2 15 1...
result:
ok edges: 362113
Test #10:
score: 0
Accepted
time: 513ms
memory: 29144kb
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:
358378 0 1 2 0 2 3 1 2 3 3 4 5 3 5 6 4 5 6 6 7 8 6 8 9 7 8 9 9 10 11 9 11 12 10 11 12 12 13 14 12 14 15 13 14 15 0 3 6 0 6 9 0 9 12 0 12 15 3 6 9 3 9 12 3 12 15 6 9 12 6 12 15 9 12 15 0 3 4 0 4 5 0 6 7 0 7 8 0 9 10 0 10 11 0 12 13 0 13 14 11 12 15 10 11 15 8 9 15 7 8 15 5 6 15 4 5 15 2 3 15 1 2 15 1...
result:
ok edges: 358378
Extra Test:
score: 0
Extra Test Passed