Submission #794253

#TimeUsernameProblemLanguageResultExecution timeMemory
794253denniskimModern Machine (JOI23_ho_t5)C++17
3 / 100
3049 ms1260 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef __int128 lll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ld, ld> pld; #define MAX 9223372036854775807LL #define MIN -9223372036854775807LL #define INF 0x3f3f3f3f3f3f3f3f #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10); #define sp << " " #define en << "\n" #define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end()) ll n, m; char s[120010], s2[120010]; ll a[120010]; ll q; ll L, R; ll rd, bl; ll numR, numB; int main(void) { fastio cin >> n >> m; for(ll i = 1 ; i <= n ; i++) { cin >> s[i]; s2[i] = s[i]; } for(ll i = 1 ; i <= m ; i++) cin >> a[i]; cin >> q; while(q--) { cin >> L >> R; rd = bl = 0; numR = numB = 0; for(ll i = 1 ; i <= n ; i++) s[i] = s2[i]; for(ll i = 1 ; i <= n ; i++) { if(s[i] == 'R') numR++; else numB++; } for(ll i = 1 ; i <= n ; i++) { if(s[i] == 'R') rd++; else break; } for(ll i = n ; i >= 1 ; i--) { if(s[i] == 'B') bl++; else break; } for(ll i = L ; i <= R ; i++) { while(rd < n) { if(s[rd + 1] == 'B') break; rd++; } while(bl < n) { if(s[n - bl] == 'R') break; bl++; } if(rd + bl >= n) { if(a[i] <= numR) numR = (numR + a[i]) % (n + 1); else numR = (numR + a[i] + 1) % (n + 1); } else { if(s[a[i]] == 'B') { numR++; numB--; s[a[i]] = 'R'; } if(numB >= a[i]) { ll num = a[i]; while(num) { if(s[rd + 1] == 'B') { num--; numR++; numB--; s[rd + 1] = 'R'; } rd++; } } else { ll num = n + 1 - a[i]; while(num) { if(s[n - bl] == 'R') { num--; numB++; numR--; s[n - bl] = 'B'; } bl++; } } } } cout << numR en; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...