QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#667555 | #5541. Substring Sort | kai824 | RE | 0ms | 3680kb | C++17 | 2.3kb | 2024-10-23 00:08:49 | 2024-10-23 00:08:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define eb emplace_back
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
#define F first
#define S second
#define rep(i,a,b) for(int i=a;i<(b);i++)
const int mxn=1e5+5;
const int BUCK=330;
int n,q;
string parts[3][mxn/BUCK];
int rankk[3][mxn/BUCK];
void split(string s,int ind){
for(int i=0;i<s.length();i+=BUCK){
parts[ind][i/BUCK]=s.substr(i,BUCK);
}
}
void upd_rankk(int i){
if(parts[i][0]<parts[i][1]){
rankk[i][0]=1;rankk[i][1]=2;
if(parts[i][1]<parts[i][2])rankk[i][2]=3;
else rankk[i][2]=0;
}else{
rankk[i][1]=1;rankk[i][0]=2;
if(parts[i][0]<parts[i][2])rankk[i][2]=3;
else rankk[i][2]=0;
}
}
void move(int i1,int i2,int st,int en){
string s1=parts[i1][st/BUCK].substr(st%BUCK);
string s2=parts[i2][st/BUCK].substr(st%BUCK);
int j = st - (st%BUCK) + BUCK;
if(s1>s2)goto swapp;
for(int j=st/BUCK + 1;j<(en/BUCK);j++){
if(rankk[i1][j]>rankk[i2][j])goto swapp;
}
s1=parts[i1][en/BUCK].substr(0,en%BUCK + 1);
s2=parts[i2][en/BUCK].substr(0,en%BUCK + 1);
if(s1>s2)goto swapp;
return;
swapp:;
s1=parts[i1][st/BUCK].substr(st%BUCK);//suffix of bucket
s2=parts[i2][st/BUCK].substr(st%BUCK);
parts[i1][st/BUCK] = parts[i1][st/BUCK].substr(0,st%BUCK) +s2;
parts[i2][st/BUCK] = parts[i2][st/BUCK].substr(0,st%BUCK) +s1;
upd_rankk(st/BUCK);
for(int j=st/BUCK + 1;j<(en/BUCK);j++){
swap(parts[i1][j],parts[i2][j]);
swap(rankk [i1][j],rankk [i2][j]);
}
s1=parts[i1][en/BUCK].substr(en%BUCK + 1);
s2=parts[i2][en/BUCK].substr(en%BUCK + 1);
parts[i1][en/BUCK] = parts[i1][en/BUCK].substr(0,en%BUCK+1) + s2;
parts[i2][en/BUCK] = parts[i2][en/BUCK].substr(0,en%BUCK+1) + s1;
upd_rankk(en/BUCK);
}
void output(){
for(int i=0;i<3;i++){
for(int j=0;j<=(n-1)/BUCK;j++)cout<<parts[i][j];
cout<<'\n';
}
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>n>>q;
rep(i,0,3){
string s;
cin>>s;
split(s,i);
}
for(int i=0;i<n;i+=BUCK){
upd_rankk(i);
}
rep(i,0,q){
int a,b;cin>>a>>b;
a--;b--;//zero-indexed: [a,b]
move(0,1,a,b);
move(1,2,a,b);
move(0,1,a,b);
// output();
}
output();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
5 2 icpca siaja karta 2 4 1 5
output:
iarta kiaja scpca
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
6 6 aabbcc bcacab cbcaba 1 1 2 2 3 3 4 4 5 5 6 6
output:
aaaaaa bbbbbb cccccc
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
3 1 aba aab aac 1 3
output:
aab aac aba
result:
ok 3 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
1 1 z y x 1 1
output:
x y z
result:
ok 3 lines
Test #5:
score: -100
Runtime Error
input:
100000 100000 llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll...