QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404160#6820. Youth FinalejiajieshiWA 0ms9768kbC++2010.5kb2024-05-03 14:27:202024-05-03 14:27:21

Judging History

你现在查看的是最新测评结果

  • [2024-05-03 14:27:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9768kb
  • [2024-05-03 14:27:20]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long 
#define pii pair<int,int>
#define pss pair<string,string>
#define fi first
#define se second
#define pb push_back
#define pbb pair<bool,bool>
#define un unsigned
#define ull unsigned long long
#define	int_INF 0x3f3f3f3f
#define LL long long
#define ll_INF 0x3f3f3f3f3f3f3f3f
#define lb long double
#define db double
#define re return
#define pll pair<ll,ll>
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define debug(a) cout<<"debug: "<<(#a)<<" = "<<a<<'\n'
#define cer(a) cerr<<#a<<'='<<(a)<<"@ line"<<__LINE__<<endl
#define cer2(a,b) cerr<<#a<<'='<<(a)<<','<<#b<<'='<<(b)<<"@ line"<<__LINE__<<endl
#define cer3(a,b,c) cerr<<#a<<'='<<(a)<<','<<#b<<'='<<(b)<<','<<#c<<'='<<(c)<<','<<"@ line"<<__LINE__<<endl
#define pdd pair<db,db>
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define KV(x) #x << " = " << x << ";"
#define DEBUG DebugLine(__LINE__)
#define bitCount(x) __builtin_popcount(x)
using namespace std;
const int maxn=3e5+100;
const ll mode=998244353;
const ll mode2=1e9+7;
const ll inf=9223372036854775807;
const db eps=1e-6;
typedef pair<int,int> hashv;
mt19937 mrand(random_device{}()); 
hashv operator + (hashv a,hashv b) {
	int c1=a.fi+b.fi,c2=a.se+b.se;
	if (c1>=mode) c1-=mode;
	if (c2>=mode2) c2-=mode2;
	return mp(c1,c2);
}

hashv operator - (hashv a,hashv b) {
	int c1=a.fi-b.fi,c2=a.se-b.se;
	if (c1<0) c1+=mode;
	if (c2<0) c2+=mode2;
	return mp(c1,c2);
}

hashv operator * (hashv a,hashv b) {
	return mp(1ll*a.fi*b.fi%mode,1ll*a.se*b.se%mode2);
}
int rnd(int x) { return mrand() % x;}
struct DebugLine {
  explicit DebugLine(int lineno) { std::cerr << lineno << "L "; }
 
  ~DebugLine() { std::cerr << std::endl; }
 
  template <typename T> DebugLine &operator<<(T &&v) {
    std::cerr << std::forward<T>(v);
    return *this;
  }
};
double PI = 3.141592653;
double my_cos(double x){
    return cos(x*PI / 180.0);
}
double my_sin(double x){
    return sin(x*PI / 180.0);
}
double my_tan(double x){
    return tan(x*PI / 180.0);
}
ll n,m,a[maxn];
ll sum,ans;
string str;
vector<int>vt;
int vis[maxn]; 
ll ksm(ll a,ll b,ll p)
{
	ll res=1ll;
	while(b)
	{
		if(b&1)
		res=res*a%p;
		b>>=1;
		a=a*a%p;
	}
	return res;
}
struct Hash_char{
    const ll mod=998244353, base=131;
    ll p[maxn], g[maxn];
    void getp(){
        p[0]=1;
        for(int i=1; i<maxn; i++){
            p[i]=p[i-1]*base%mod;
        }
    }
    LL Hash(char s[]){
        int len=strlen(s+1);
        g[0]=0, g[1]=s[1];
        for(int i=2; i<=len; i++){
            g[i]=(g[i-1]*base+s[i])%mod;
        }
        return g[len];
    }
    LL getLR(int l, int r){//µÃµ½s[l]-s[r]µÄhashÖµ 
        if(l>r) return 0;
        LL ans=((g[r]-g[l-1]*p[r-l+1])%mod+mod)%mod;
        return ans;
    }
    
 
}T[2];
LL strfz(int pos, int l, int r){//pos:Õý·´´®,·­×ªl, r¡£ 
    LL ans=T[pos].getLR(1, l-1)*T[pos].p[n-l+1]%T[pos].mod;
    LL res=T[pos^1].getLR(n-r+1, n-r+1+r-l)*T[pos].p[n-r]%T[pos].mod;
    ans=ans+res+T[pos].getLR(r+1, n);
    return ans%T[pos].mod;
}

template<const int T>
struct ModInt {
    const static int mod = T;
    int x;
    ModInt(int x = 0) : x(x % mod) {}
    ModInt(long long x) : x(int(x % mod)) {} 
    int val() { return x; }
    ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
    ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
    ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
    bool operator == (const ModInt &a) const { return x == a.x; };
    bool operator != (const ModInt &a) const { return x != a.x; };
    void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
    void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
    void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
    void operator /= (const ModInt &a) { *this = *this / a; }
    friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
    friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
    friend ModInt operator * (int y, const ModInt &a){ return ModInt(1LL * y * a.x % mod);}
    friend ModInt operator / (int y, const ModInt &a){ return ModInt(y) / a;}
    friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
    friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}
 
    ModInt pow(int64_t n) const {
        if(n == 0) return 1;
        ModInt res(1), mul(x);
        while(n){
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
     
    ModInt inv() const {
        int a = x, b = mod, u = 1, v = 0;
        while (b) {
            int t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        if (u < 0) u += mod;
        return u;
    }
     
};
using mint = ModInt<1000000007>;
ll ecgcd(ll a,ll b,ll& x,ll& y)
{
    if(b==0)
    {
        x=1,y=0;
        return a;
    }
    ll d=ecgcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
//class manacherWrapper
//{
//    private:
//        int l_;
//        string s_;
//    public:
//        std::vector<int> p;
//        std::vector<int> b;
//        std::vector<int> s;
//        explicit manacherWrapper(string str)
//        {
//            auto l = str.size();
//            //rebuild
//            l_ = l;
//            s_.resize(((l_ + 1) << 1) | 1);
//            p.resize(((l_ + 1) << 1) | 1);
//            b.resize(l_);
//            s.resize(l_ + 1);
// 
//            s_[0] = '$', s_[1] = '#';
// 
//            for (int i = 0; i < l_; ++i)
//                s_[(i + 1) << 1] = str[i], s_[((i + 1) << 1) | 1] = '#';
//            l_ = (l_ + 1) << 1;
//            //calc p
//            int mx = 0, id;
//            for (int i = 0; i < l_; ++i)
//            {
//                if (mx > i)p[i] = std::min(p[(id << 1) - i], mx - i);
//                else p[i] = 1;
//                for (; s_[i - p[i]] == s_[i + p[i]]; p[i]++);
//                if (p[i] + i > mx)
//                {
//                    mx = p[i] + i;
//                    id = i;
//                }
//            }
//            //calc b and s
//            for (int i = 0; i < l; ++i)
//            {
//                auto lp = get(i);
//                b[i - (lp >> 1)] = std::max(b[i - (lp >> 1)], lp);
//                s[i - (lp >> 1)]++, s[i + 1]--;
//                if (i + 1 >= l)break;
//                lp = get(i, i + 1);
//                if (lp > 0)
//                {
//                    b[i + 1 - (lp >> 1)] = std::max(b[i + 1 - (lp >> 1)], lp);
//                    s[i + 1 - (lp >> 1)]++, s[i + 1]--;
//                }
//            }
//            for (int i = 1; i < l; ++i)
//            {
//                b[i] = std::max(b[i], b[i - 1] - 2);
//                s[i] += s[i - 1];
//            }
//        }
// 
//        int get(int pos)
//        {
//            return (int) p[(pos + 1) << 1] - 1;
//        }
// 
//        int get(int posl, int posr)
//        {
//            return (int) p[((posl + 1) << 1) | 1] - 1;
//        }
// 
//        int longestBegin(int begin)
//        {
//            return b[begin];
//        }
// 
//        int totalBegin(int begin)
//        {
//            return s[begin];
//        }
// 
//        bool isPalindrome(int l,int r)
//        {
//            if (l > r)std::swap(l, r);
//            auto mid = (l + r) >> 1;
//            auto len = (r - l + 1);
//            return len & 1 ? get(mid) >= len : get(mid, mid + 1) >= len;
//        }
//};
//void scan(__int128 &x){//input
//	x = 0;
//	int f = 1;
//	char ch;
//	if((ch = getchar()) == '-'){
//		f = -1;
//	}else{
//		x = x * 10 + (ch - '0');
//	}
//	while((ch = getchar()) >= '0' && ch <= '9'){
//		x = x * 10 + (ch - '0');
//	}
//	x *= f;
//}
//void print(__int128 x){//output 
//	if(x < 0){
//		x = -x;
//		putchar('-');
//	}
//	if(x > 9){
//		print(x/10);//recursion
//	}
//	putchar(x%10+'0');
//}
ll tr[maxn];
int ne[maxn],pre[maxn];
int lowbit(int x)
{
	return x&(-x);
}
void add(int x)
{
	for(int i=x;i<=n;i+=lowbit(i))
	tr[i]++;
}
ll query(int x)
{
	ll res=0;
	for(int i=x;i;i-=lowbit(i))
	res+=tr[i];
	return res;
}
void solve()
{
	cin>>n>>m;
	int op=0;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	ll last=0;
	for(int i=1;i<=n;i++)
	{
		ll v=i-1-query(a[i]-1);
		last+=v;
		add(a[i]);
	}
	a[n+1]=n+1;
	for(int i=1;i<=n;i++)
	{
		ne[a[i]]=a[i+1];
	}
	ne[0]=a[1];
	for(int i=n;i>=1;i--)
	{
		pre[a[i]]=a[i-1];
	}
	pre[n+1]=a[n];
//	cer(ans);
//    cer2(ne[0],pre[n+1]);
	cin>>str;
	cout<<last<<'\n';
	for(int i=1;i<=m;i++)
	{
		if(str[i-1]=='S')
		{
			if(op==1)
			{
				ans=last-(pre[n+1]-1)+n-pre[n+1];
//				ne[pre[n+1]]=ne[0];
//				ne[pre[pre[n+1]]]=n+1;
//				pre[ne[0]]=pre[n+1];
//				ne[0]=pre[n+1];
//				pre[n+1]=pre[pre[n+1]];
//				pre[ne[0]]=0;
                int st1=ne[0];
                int ed1=pre[n+1];
                int st2=ne[ne[0]];
                int ed2=pre[pre[n+1]];
                ne[0]=ed1;
                pre[ed1]=0;
                ne[ed1]=st1;
				pre[st1]=ed1;
                pre[n+1]=ed2;
                ne[ed2]=n+1;
			}else{
				ans=last-(ne[0]-1)+n-ne[0];
//				ne[pre[n+1]]=ne[0];
//				pre[ne[0]]=pre[n+1];
//				pre[n+1]=ne[0];
//				ne[0]=ne[ne[0]];
                int st1=ne[0];
                int ed1=pre[n+1];
                int st2=ne[ne[0]];
                int ed2=pre[pre[n+1]];
                ne[0]=st2;
                pre[st1]=ed1;
                ne[st1]=n+1;
                pre[st2]=0;
                ne[ed1]=st1;
                pre[n+1]=st1;
			}
			last=ans;
			ans=(ans%10)+10;
			ans%=10;
			cout<<ans<<' ';
			continue;
		}
		
		op^=1;
		ans=(n-1)*n/2-last;
//		cer2(i,ans);
		last=ans;
		ans=(ans%10+10)%10;
		cout<<ans<<" ";
	}
	
}
int main(){
	#ifndef ONLINE_JUDGE
		freopen("C:\\Users\\JIAJIEASHI\\Desktop\\in.cpp","r",stdin);
	//	freopen("out.cpp","w",stdout);
	#endif
    ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int test_case;
	test_case=1;
//	cin>>test_case;
	while(test_case--) 
    solve();
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 9768kb

input:

5 10
5 4 3 2 1
SSSSRSSSSR

output:

10
6 4 4 6 4 6 6 4 0 0 

result:

wrong answer 2nd words differ - expected: '6446466400', found: '6'