QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#425751 | #6106. Making Number | HKOI0# | WA | 37ms | 10596kb | C++20 | 3.1kb | 2024-05-30 16:37:07 | 2024-05-30 16:37:09 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
struct BIT {
int n;
vector<vi> a;
BIT(int n) : n(n), a(n+2, vi(10)) {}
void add(int i, int j, int num) {
for(;i<=n;i+=i&-i) a[i][j]+=num;
}
};
void solve() {
string s1,s2;
cin>>s1>>s2;
int n=sz(s1);
vector<int> sum(10);
for(auto c:s1) sum[c-'0']++;
BIT bit(n);
for(int i=1;i<=n;i++) bit.add(i,s2[i-1]-'0',1);
int q;
cin>>q;
int mx=0;
while(1<<(mx+1)<=n) mx++;
while(q--) {
int t;
cin>>t;
if(t==1) {
int i,x;
cin>>i>>x;
bit.add(i,s2[i-1]-'0',-1);
bit.add(i,x,1);
s2[i-1]=x+'0';
}
else {
int i;
cin>>i;
int ans=0;
vector<int> prev(10);
for(int j=mx;j>=0;j--) {
if(ans+(1<<j)>n) continue;
auto cur=prev;
for(int k=0;k<10;k++) cur[k]+=bit.a[ans+(1<<j)][k];
auto ok = [&] {
for(int k=0;k<10;k++)
if(sum[k]<cur[k]) return false;
if(ans+(1<<j)==n) return true;
int next_bit = s2[ans+(1<<j)]-'0';
for(int k=next_bit+1;k<10;k++)
if(sum[k]-cur[k]) return true;
return false;
};
if(ok()) {
ans+=1<<j;
prev=cur;
}
}
if(i<=ans) cout<<s2[i-1]<<'\n';
else {
if(ans==0) {
int first_bit = s2[0]-'0';
bool ok=false;
for(int k=first_bit+1;k<10;k++)
if(sum[k]) ok=true;
if(!ok) {
cout<<"-1\n";
continue;
}
}
auto diff=sum;
for(int j=0;j<10;j++) diff[j]-=prev[j];
int remain=i-ans;
int next_bit=s2[ans]-'0';
int fi=0;
for(int j=next_bit+1;j<10;j++)
if(diff[j]) {
diff[j]--;
remain--;
fi=j;
break;
}
if(remain==0) {
cout<<fi<<'\n';
continue;
}
for(int j=0;j<10;j++) {
if(remain<=diff[j]) {
cout<<j<<'\n';
break;
}
else remain-=diff[j];
}
}
}
}
}
int main() {
#ifndef LOCAL
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int T = 1;
// cin >> T;
while (T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
3304 1615 6 2 3 2 4 1 1 3 2 2 1 2 4 2 1
output:
3 4 0 3
result:
ok 4 number(s): "3 4 0 3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
838046 780357 10 2 1 2 2 1 2 4 2 3 2 4 1 4 5 2 5 2 6 1 1 9 2 2
output:
8 0 3 4 6 8 -1
result:
ok 7 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2950 9052 4 2 1 2 2 2 3 2 4
output:
9 0 5 2
result:
ok 4 number(s): "9 0 5 2"
Test #4:
score: -100
Wrong Answer
time: 37ms
memory: 10596kb
input:
677626993975892499704039030543272430899275243910257911804799779050091046516452988178013531014268918811173939650642586439566406179191340032290242471164620397693718115937469230865639050202204033086180013798392250945514997389392089836361472892923108709052296874567465127993121832785182254870655135620662...
output:
9 7 3 6 7 8 7 1 8 7 1 5 8 4 1 1 3 0 3 8 4 9 5 9 1 5 6 1 3 9 4 7 2 1 4 0 2 0 1 0 3 7 0 8 1 9 9 4 4 2 6 4 8 9 5 6 3 3 2 4 7 6 2 4 9 5 4 8 2 0 4 4 2 0 7 2 8 4 6 9 9 1 3 6 8 0 9 6 5 8 9 1 5 4 3 5 9 7 2 0 0 9 2 0 3 9 9 6 8 2 9 2 9 6 1 7 3 8 9 6 4 8 3 5 4 5 5 7 4 1 1 5 7 9 8 9 8 7 5 5 0 8 9 8 5 5 0 2 8 0 ...
result:
wrong answer 1st numbers differ - expected: '7', found: '9'