QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#622241 | #6820. Youth Finale | Sound_Medium | WA | 1ms | 7764kb | C++23 | 1.5kb | 2024-10-08 20:26:56 | 2024-10-08 20:27:00 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define lowbit(x) (x&(-x))
int n, m;
const int N=3e5+10;
int a[N],tr[N];
const int mod=10;
void add(int x,int k){
for(int i=x;i<N;i+=lowbit(i)){
tr[i]+=k;
}
}
int query(int x){
int ans=0;
for(int i=x;i>0;i-=lowbit(i)){
ans+=tr[i];
}
return ans;
}
int query(int l,int r){
return query(r)-query(l-1);
}
void solve () {
cin>>n>>m;
deque<int>q;
array<int,2>ans={0,0};
for(int i=1;i<=n;i++){
cin>>a[i],q.push_back(a[i]);
ans[0]+=query(a[i],n);
ans[1]+=query(a[i]);
ans[0]%=10;
ans[1]%=10;
add(a[i],1);
}
string s;
cin>>s;
int f=0;
for(auto v:s){
if(v=='S'){
if(f==1){
int k=q.back();
q.pop_back();
q.push_front(k);
ans[f]=(ans[f]-(k-1)+n-k+100000)%mod;
ans[f^1]=(ans[f^1]-(n-k)+k-1+100000)%mod;
}else{
int k=q.front();
q.pop_front();
q.push_back(k);
ans[f]=(ans[f]-(k-1)+n-k+100000)%mod;
ans[f^1]=(ans[f^1]-(n-k)+k-1+100000)%mod;
}
}else{
f^=1;
// swap(ans[0],ans[1]);
}
cout<<(ans[f]%10);
}
}
signed main () {
int T = 1;
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//cin>>T;
while (T --) solve ();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7764kb
input:
5 10 5 4 3 2 1 SSSSRSSSSR
output:
6446466400
result:
wrong answer 1st words differ - expected: '10', found: '6446466400'