QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#528961 | #1350. Mango | 36champ | WA | 1ms | 4372kb | C++20 | 3.1kb | 2024-08-24 04:58:59 | 2024-08-24 04:59:00 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
void query1(ll l, ll r, ll n, string &a, vector<string> &str)
{
if(str[0].size() != 0 && l <= n * (ll) str[0].size())
{
for(ll i = l; i <= min(n * (ll) str[0].size(), r); i++) cout << str[0][(i - 1) % str[0].size()];
}
l = min(1LL, l - n * (ll) str[0].size());
r -= n * (ll) str[0].size();
if(r <= 0) return;
for(ll i = l; i <= min((ll) a.size(), r); i++) cout << a[i - 1];
l = min(1LL, l - (ll) a.size());
r -= a.size();
if(r <= 0) return;
for(ll i = l; i <= min(n * (ll) str[1].size(), r); i++) cout << str[1][(i - 1) % str[1].size()];
}
void query(ll l, ll r, ll n, string &a, vector<string> &str, vector<ll> &len)
{
//cout << "Q " << l << " " << r << " " << n << "\n";
if(l > r || l < 1 || r < 1) return;
if(n == 0)
{
for(ll i = l; i <= r; i++) cout << a[i - 1];
return;
}
if(n > (ll) len.size())
{
for(ll i = l; i <= min((ll) (n - len.size()) * (ll) str[0].size(), r); i++)
{
cout << str[0][(i - 1) % str[0].size()];
}
return query(max(1LL, l - (ll) (n - len.size()) * (ll) str[0].size()), r - (ll) (n - len.size()) * (ll) str[0].size(), len.size(), a, str, len);
}
for(int j = 0; j < (ll) str.size(); j++)
{
if(l <= (ll) str[j].size())
{
//cout << "! " << j << " " << l << " " << str[j].size() << " " << min(l + (ll) str[j].size() - 1, r) << "\n";
for(ll i = l; i <= min((ll) str[j].size(), r); i++) cout << str[j][i - 1];
}
l = max(1LL, l - (ll) str[j].size());
r -= (ll) str[j].size();
if(r <= 0) return;
if(l <= len[n - 1]) query(l, min(len[n - 1], r), n - 1, a, str, len);
l = max(1LL, l - len[n - 1]);
r -= len[n - 1];
if(r <= 0) return;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
string a, s;
cin >> a >> s;
ll n, q;
cin >> n >> q;
ll cnt = 0;
for(char c: s) if(c == '$') cnt++;
vector<string> str;
string now;
for(char c: s)
{
if(c == '$')
{
str.pb(now);
now = "";
continue;
}
now += c;
}
str.pb(now);
/*for(string x: str) cout << x << " ";
cout << "\n";
for(string x: str) cout << x.size() << " ";
cout << "\n";*/
ll l = a.size();
vector<ll> len;
for(int i=0; i<n; i++)
{
len.pb(l);
if(l - 1 > ((1LL<<60) / cnt)) break;
l = (l - 1) * cnt + s.size();
}
/*for(ll l: len) cout << l << " ";
cout << "\n";*/
while(q-->0)
{
ll l, r;
cin >> l >> r;
if(cnt == 1) query1(l, r, n, a, str);
else query(l, r, n, a, str, len);
cout << "\n";
}
}
/*
It's_a_cat,_not_a_mango
It's_"$",_not_"$"
1 6
1 20
18 35
49 61
29 40
41 50
5 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3508kb
input:
It's_a_cat,_not_a_mango It's_"$",_not_"$" 1 6 1 20 18 35 49 61 29 40 41 50 5 5
output:
It's_"It's_a_cat,_no _not_a_mango",_not _not_a_mango" o",_not_"It' s_a_cat,_n _
result:
ok 6 tokens
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4372kb
input:
Ad_finitum $ 100000 4 1 10 1 2 4 10 5 8
output:
Ad_finitum Ad Ad_finitum Ad_finit
result:
wrong answer 3rd words differ - expected: 'finitum', found: 'Ad_finitum'