提出 #34346244


ソースコード 拡げる

#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define db double
#define pb push_back
#define int ll
#define ull unsigned long long
using namespace std;
int n,a[100005],Q;
struct node {
    ll c[3][3],d[3];
    int fa[3];
}t[400005];
void add(int p,int *c) {
    ll c2[3][3],d2[3],fa2[3];for(int i=0;i<3;i++) for(int j=0;j<3;j++) c2[i][j]=0;
    for(int i=0;i<3;i++) d2[i]=0;for(int i=0;i<3;i++) d2[c[i]]+=t[p].d[i];for(int i=0;i<3;i++) t[p].d[i]=d2[i];
    for(int i=0;i<3;i++) {
        for(int j=0;j<3;j++) {
            c2[c[i]][c[j]]+=t[p].c[i][j];
        }
    }for(int i=0;i<3;i++) for(int j=0;j<3;j++) t[p].c[i][j]=c2[i][j];
    for(int i=0;i<3;i++) fa2[i]=c[t[p].fa[i]];for(int i=0;i<3;i++) t[p].fa[i]=fa2[i];
}
void pushdown(int p) {
    add(p<<1,t[p].fa),add(p<<1|1,t[p].fa);
    for(int i=0;i<3;i++) t[p].fa[i]=i;
} 
node merge(node x,node y) {
    node z;for(int i=0;i<3;i++) z.d[i]=x.d[i]+y.d[i],z.fa[i]=i;
    for(int i=0;i<3;i++) for(int j=0;j<3;j++) z.c[i][j]=x.c[i][j]+y.c[i][j]+x.d[i]*y.d[j];
    return z;
}
void build(int p,int l,int r) {
    for(int i=0;i<3;i++) t[p].fa[i]=i;
    if(l==r) {t[p].d[a[l]]++;return;}
    int mid=l+r>>1;build(p<<1,l,mid),build(p<<1|1,mid+1,r);
    t[p]=merge(t[p<<1],t[p<<1|1]);
}
node qry(int p,int l,int r,int ql,int qr) {
    if(ql<=l&&r<=qr) return t[p];
    int mid=l+r>>1;pushdown(p);
    if(qr<=mid) return qry(p<<1,l,mid,ql,qr);
    if(mid<ql) return qry(p<<1|1,mid+1,r,ql,qr);
    return merge(qry(p<<1,l,mid,ql,qr),qry(p<<1|1,mid+1,r,ql,qr));
}
void upd(int p,int l,int r,int ql,int qr,int *c) {
    if(ql<=l&&r<=qr) {add(p,c);return;}
    int mid=l+r>>1;pushdown(p);
    if(ql<=mid) upd(p<<1,l,mid,ql,qr,c);
    if(mid<qr) upd(p<<1|1,mid+1,r,ql,qr,c);
    t[p]=merge(t[p<<1],t[p<<1|1]);
}
signed main() {
    //freopen("fuck.in","r",stdin);
    cin>>n>>Q;
    for(int i=1;i<=n;i++) cin>>a[i];
    build(1,1,n);
    for(int i=0;i<Q;i++) {
        int op,l,r,c[3];
        cin>>op>>l>>r;
        if(op==1) {
            node res=qry(1,1,n,l,r);ll tot=0;
            for(int i=0;i<3;i++) for(int j=0;j<i;j++) tot+=res.c[i][j];
            cout<<tot<<endl;
        }
        else {
            cin>>c[0]>>c[1]>>c[2];
            upd(1,1,n,l,r,c);
        }
    }
}

提出情報

提出日時
問題 G - 012 Inversion
ユーザ duanyu
言語 C++ (GCC 9.2.1)
得点 600
コード長 2329 Byte
結果 AC
実行時間 468 ms
メモリ 35152 KiB

コンパイルエラー

./Main.cpp: In function ‘void add(long long int, long long int*)’:
./Main.cpp:17:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   17 |     for(int i=0;i<3;i++) d2[i]=0;for(int i=0;i<3;i++) d2[c[i]]+=t[p].d[i];for(int i=0;i<3;i++) t[p].d[i]=d2[i];
      |     ^~~
./Main.cpp:17:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   17 |     for(int i=0;i<3;i++) d2[i]=0;for(int i=0;i<3;i++) d2[c[i]]+=t[p].d[i];for(int i=0;i<3;i++) t[p].d[i]=d2[i];
      |                                  ^~~
./Main.cpp:23:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   23 |     for(int i=0;i<3;i++) fa2[i]=c[t[p].fa[i]];for(int i=0;i<3;i++) t[p].fa[i]=fa2[i];
      |     ^~~
./Main.cpp:23:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   23 |     for(int i=0;i<3;i++) fa2[i]=c[t[p].fa[i]];for(int i=0;i<3;i++) t[p].fa[i]=fa2[i];
      |                                               ^~~
./Main.cpp: In function ‘void build(long long int, long long int, long long int)’:
./Main.cpp:37:14: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   37 |     int mid=l+r>>1;build(p<<1,l,mid),build(p<<1|1,mid+1,r);
      |             ~^~
./Main.cpp: In function ‘node qry(long long int, long long int, long long int, long long int, long long int)’:
./Main.cpp:42:14: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   42 |     int mid=l+r>>1;pushdown(p);
      |             ~^~
./Main.cpp: In function ‘void upd(long long int, long long int, long long int, long long int, long long int, long long int*)’:
./Main.cpp:49:14: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   49 |     int mid=l+r>>1;pushdown(p);
      |             ~^~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 2
AC × 22
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 409 ms 34992 KiB
random_02.txt AC 150 ms 35016 KiB
random_03.txt AC 425 ms 34868 KiB
random_04.txt AC 324 ms 34928 KiB
random_05.txt AC 453 ms 34920 KiB
random_06.txt AC 277 ms 7504 KiB
random_07.txt AC 391 ms 35044 KiB
random_08.txt AC 68 ms 11384 KiB
random_09.txt AC 428 ms 35048 KiB
random_10.txt AC 311 ms 34976 KiB
random_11.txt AC 468 ms 35084 KiB
random_12.txt AC 109 ms 19072 KiB
random_13.txt AC 459 ms 34868 KiB
random_14.txt AC 187 ms 3368 KiB
random_15.txt AC 39 ms 35048 KiB
random_16.txt AC 2 ms 3540 KiB
random_17.txt AC 374 ms 35048 KiB
random_18.txt AC 372 ms 35096 KiB
random_19.txt AC 371 ms 35056 KiB
random_20.txt AC 373 ms 35152 KiB
sample_01.txt AC 4 ms 3428 KiB
sample_02.txt AC 2 ms 3588 KiB