QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#805025 | #9791. Intrusive Donkey | ucup-team902# | WA | 1ms | 7952kb | C++20 | 2.5kb | 2024-12-08 11:52:42 | 2024-12-08 11:52:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e5;
int n,q;
char s[N+5];
int m;
struct val{
char c; ll l;
}x[N+5];
struct Segtr{
ll tr[N*4+5],tag[N*4+5];
#define lc id<<1
#define rc id<<1|1
void build(int l,int r,int id){
tag[id]=1;
if(l==r){
tr[id]=x[l].l;
return;
}
int mid=l+r>>1;
build(l,mid,lc);
build(mid+1,r,rc);
tr[id]=tr[lc]+tr[rc];
}
void push_down(int id){
if(tag[id]==1) return;
ll t=tag[id]; tag[id]=1;
tr[lc]*=t; tag[lc]*=t;
tr[rc]*=t; tag[rc]*=t;
}
void upd(int l,int r,int p,int id){
if(l==r){
tr[id]=x[p].l;
return;
}
int mid=l+r>>1;
push_down(id);
if(p<=mid) upd(l,mid,p,lc);
else upd(mid+1,r,p,rc);
tr[id]=tr[lc]+tr[rc];
}
void mul(int l,int r,int st,int en,int id){
if(st<=l&&en>=r){
tr[id]*=2; tag[id]*=2;
return;
}
int mid=l+r>>1;
push_down(id);
if(st<=mid) mul(l,mid,st,en,lc);
if(en>mid) mul(mid+1,r,st,en,rc);
tr[id]=tr[lc]+tr[rc];
}
pair<ll,int> query(int l,int r,ll s,int id){
if(l==r) return {s,l};
int mid=l+r>>1;
push_down(id);
if(s<=tr[lc]) return query(l,mid,s,lc);
else return query(mid+1,r,s-tr[lc],rc);
}
}T;
int main(){
scanf("%d %d",&n,&q);
scanf("%s",s+1);
for(int i=1;i<=n;i++)
if(s[i]==s[i-1])
x[m].l++;
else
x[++m]={s[i],1};
T.build(1,m,1);
while(q--){
int tp; ll l,r;
scanf("%d",&tp);
if(tp==1){
scanf("%lld %lld",&l,&r);
auto [ll,lp]=T.query(1,n,l,1);
auto [rr,rp]=T.query(1,n,r,1);
if(lp==rp){
x[lp].l+=rr-ll+1;
T.upd(1,m,lp,1);
}
else{
x[lp].l+=x[lp].l-ll+1;
x[rp].l+=rr;
T.upd(1,m,lp,1);
T.upd(1,m,rp,1);
for(int j=lp+1;j<rp;j++)
x[j].l*=2;
if(lp+1<rp)
T.mul(1,m,lp+1,rp-1,1);
}
}
else{
scanf("%lld",&l);
auto [ll,lp]=T.query(1,n,l,1);
putchar(x[lp].c);
puts("");
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7848kb
input:
4 7 abac 2 2 2 3 1 2 3 2 3 2 4 2 5 2 6
output:
b a b a a c
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 7904kb
input:
5 4 shrek 1 1 2 2 7 1 1 7 2 7
output:
k h
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 7704kb
input:
4 7 abac 2 2 2 3 1 2 3 2 3 2 4 2 5 2 6
output:
b a b a a c
result:
ok 6 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 7756kb
input:
5 4 shrek 1 1 2 2 7 1 1 7 2 7
output:
k h
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 7828kb
input:
3 55 vfe 1 2 3 1 2 2 1 3 5 2 4 1 1 2 2 9 2 7 2 5 1 10 10 1 1 1 2 9 1 8 12 2 8 1 7 10 2 1 1 5 6 1 1 4 1 20 24 1 14 32 1 19 38 2 48 1 56 64 2 58 2 19 1 64 72 1 36 86 2 11 1 117 124 2 38 2 108 2 85 1 112 118 2 153 2 40 2 114 2 80 1 11 18 2 27 2 73 1 159 162 2 84 1 130 164 2 163 2 65 1 150 156 1 101 109...
output:
f e f f f f v f e f f f e e e f e e f e e e f e f e v
result:
ok 27 lines
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 7952kb
input:
60 51 ranhfkbjhkxckkcbhgsspsjcbjgpwcfvmqqlvlfualndmqqsihsfdyqviowu 2 53 2 37 2 33 2 60 1 1 32 2 44 1 87 92 1 7 77 1 56 86 2 17 1 128 184 1 26 159 2 323 2 55 1 24 316 1 435 652 2 316 2 444 1 819 868 2 27 2 912 2 313 1 555 576 1 510 942 1 1118 1269 2 365 2 84 1 595 650 2 1468 2 258 1 1557 1607 2 938 1...
output:
i f l
result:
wrong answer 1st lines differ - expected: 'd', found: 'i'