QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#481146 | #21403. 文艺平衡树 | AFewSuns# | WA | 1ms | 5720kb | C++14 | 2.3kb | 2024-07-16 20:49:17 | 2024-07-16 20:49:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 1e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
#define LC lc[x]
#define RC rc[x]
mt19937 rnd(1);
ll n,m,lc[100010],rc[100010],siz[100010],rd[100010],lz[100010],rt=0;
il void pushup(ll x){
siz[x]=siz[LC]+siz[RC]+1;
}
il void pushdown(ll x){
if(!lz[x]) return;
swap(lc[LC],rc[LC]);
swap(lc[RC],rc[RC]);
lz[LC]^=1;
lz[RC]^=1;
lz[x]=0;
}
void split(ll x,ll &l,ll &r,ll v){
if(!x){
l=0;
r=0;
return;
}
pushdown(x);
if(siz[LC]>=v){
r=x;
split(LC,l,LC,v);
}
else{
l=x;
split(RC,RC,r,v-siz[LC]-1);
}
pushup(x);
}
ll merge(ll x,ll y){
if(!x) return y;
if(!y) return x;
pushdown(x);
pushdown(y);
if(rd[x]>=rd[y]){
RC=merge(RC,y);
pushup(x);
return x;
}
else{
lc[y]=merge(x,lc[y]);
pushup(y);
return y;
}
}
void query(ll x){
if(LC) query(LC);
writesp(x);
if(RC) query(RC);
}
int main(){
n=read();
m=read();
fr(i,1,n) siz[i]=1;
fr(i,1,n) rd[i]=rnd();
fr(i,1,n) rt=merge(rt,i);
while(m--){
ll l=read(),r=read(),x,y,z;
split(rt,x,z,r);
split(x,x,y,l-1);
lz[y]^=1;
swap(lc[y],rc[y]);
rt=merge(merge(x,y),z);
}
query(rt);
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5720kb
input:
30 5 7 26 7 18 5 9 4 15 3 15
output:
1 2 4 15 5 6 16 17 18 19 20 22 21 23 3 24 25 26 14 13 12 11 10 9 8 7 27 28 29 30
result:
wrong answer 1st lines differ - expected: '1 2 4 17 16 15 6 5 18 19 20 21...4 13 12 11 10 9 8 7 27 28 29 30', found: '1 2 4 15 5 6 16 17 18 19 20 22... 13 12 11 10 9 8 7 27 28 29 30 '