QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#826543#9886. Long Sequence Inversion 2ucup-team902#TL 1ms3604kbC++203.3kb2024-12-22 13:45:152024-12-22 13:45:16

Judging History

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

  • [2024-12-22 13:45:16]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3604kb
  • [2024-12-22 13:45:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define y0 sxxxxx
#define pii pair<int, int>
#define ll long long
#define fi first
#define se second
#define bg begin
namespace IO {

cs int RLEN = 1 << 22 | 1;
char ibuf[RLEN], *ib, *ob;
inline char gc() {
    (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
    return (ib == ob) ? EOF : *ib++;
}
inline int read() {
    char ch = gc();
    int res = 0;
    bool f = 1;
    while (!isdigit(ch)) f ^= ch == '-', ch = gc();
    while (isdigit(ch)) res = (res * 10) + (ch ^ 48), ch = gc();
    return f ? res : -res;
}
inline ll readll() {
    char ch = gc();
    ll res = 0;
    bool f = 1;
    while (!isdigit(ch)) f ^= ch == '-', ch = gc();
    while (isdigit(ch)) res = (res * 10) + (ch ^ 48), ch = gc();
    return f ? res : -res;
}
inline char readchar() {
    char ch = gc();
    while (isspace(ch)) ch = gc();
    return ch;
}
inline int readstring(char *s) {
    int top = 0;
    char ch = gc();
    while (isspace(ch)) ch = gc();
    while (!isspace(ch) && ch != EOF) s[++top] = ch, ch = gc();
    s[top + 1] = '\0';
    return top;
}

}  // namespace IO
using IO::read;
using IO::readchar;
using IO::readll;
using IO::readstring;
template <typename tp>
inline void chemx(tp &a, tp b) { (a < b) ? (a = b) : 0; }
template <typename tp>
inline void chemn(tp &a, tp b) { (a > b) ? (a = b) : 0; }

cs int mod=998244353;
inline int add(int a,int b){return (a+b)>=mod?(a+b-mod):(a+b);}
inline int dec(int a,int b){return (a<b)?(a-b+mod):(a-b);}
inline int mul(int a,int b){static ll r;r=(ll)a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){a=(a+b)>=mod?(a+b-mod):(a+b);}
inline void Dec(int &a,int b){a=(a<b)?(a-b+mod):(a-b);}
inline void Mul(int &a,int b){static ll r;r=(ll)a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
inline int fix(ll x){x%=mod;return (x<0)?x+mod:x;}
cs int N=500005;
int L,B;
vector<int>v[N];
struct bit{
vector<int>tr;
#define lb(x) (x&(-x))
void update(int p){
    for(;p>0;p-=lb(p))tr[p]++;
}
int query(int p,int res=0){
    for(;p<=B;p+=lb(p))res+=tr[p];return res;
}
}t1,t2;
int C(int x){
    return (1ll*x*(x-1)/2)%mod;
}
void solve(){
    L=read(),B=read();
    vector<int>p(L+1);
    for(int i=0;i<L;i++)p[i]=read();
    for(int i=0;i<L;i++){
        v[i].resize(B+1);
        for(int j=0;j<B;j++)v[i][j]=read();
    }
    int ans=0;
    t1.tr.resize(L+1);
    vector<int>id;
    for(int i=0;i<L;i++){
        int xx=i-t1.query(p[i]+1);
        t1.update(p[i]+1);
        int yy=ksm(B,p[i]-xx);
        t2.tr.clear();
        t2.tr.resize(B+1);
        int cnt=0;
        for(int j=0;j<B;j++){
            Add(cnt,t2.query(v[i][j]+1));
            t2.update(v[i][j]+1);
        }
        Mul(cnt,yy);
        Add(cnt,mul(C(yy),C(B)));
        Mul(cnt,ksm(B,xx));
        Mul(cnt,ksm(B,xx));
        Mul(cnt,ksm(B,L-1-p[i]));
        Add(ans,cnt);
    }
    cout<<ans<<'\n';
}

signed main() {
	#ifdef Stargazer
	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	#endif

    int T = 1;
    //int T=1;
    while (T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3604kb

input:

3 2
2 0 1
1 0
1 0
0 1

output:

14

result:

ok "14"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3528kb

input:

2 4
1 0
2 0 3 1
1 2 3 0

output:

60

result:

ok "60"

Test #3:

score: -100
Time Limit Exceeded

input:

9 10
2 5 7 3 8 1 4 6 0
9 2 4 0 1 6 7 3 5 8
4 1 6 7 8 0 5 9 2 3
1 9 2 4 6 8 5 7 0 3
9 0 8 2 5 1 6 7 3 4
1 6 0 7 3 9 2 4 5 8
4 5 2 9 1 6 7 3 0 8
7 0 5 6 1 9 2 4 3 8
3 2 1 6 7 0 8 9 4 5
9 2 4 3 5 8 0 6 7 1

output:


result: