Submission #35597377
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)
#define SEG_ROOT 1,0,n-1
#define SEG_L (o<<1)
#define SEG_R (o<<1|1)
#define mid (l+r)/2
#define SEG_L_CHILD SEG_L,l,mid
#define SEG_R_CHILD SEG_R,mid+1,r
ll read(){ll r;scanf("%lld",&r);return r;}
using A3=array<ll,3>;
using A33=array<A3,3>;
struct Node{
A3 a={0,0,0};
A3 lazy={0,1,2}; // 未向下传递的(本层已经作用
A33 c={{{{0,0,0}},{{0,0,0}},{{0,0,0}}}};
}seg[400010]; // seg[0] empty node
int a[100010];
template<class T>
T merge(const T&v0,const T&v1){
T v;
rep(i,0,3)v.a[i]=v0.a[i]+v1.a[i];
rep(i,0,3)rep(j,0,3)v.c[i][j]=v0.c[i][j]+v1.c[i][j];
rep(i,0,3)rep(j,0,3)if(i!=j) v.c[i][j] += v0.a[i]*v1.a[j];
return v;
}
Node build(int o,int l,int r){
if(l==r){
seg[o].a[a[l]]=1;
return seg[o];
}
return seg[o]=merge(build(SEG_L_CHILD),build(SEG_R_CHILD));
}
void zotfn(int o,const A3&zot){ // zero one two
Node newo=seg[0];
rep(i,0,3)newo.a[zot[i]]+=seg[o].a[i];
rep(i,0,3)newo.lazy[i] = zot[seg[o].lazy[i]];
rep(i,0,3)rep(j,0,3)newo.c[zot[i]][zot[j]]+=seg[o].c[i][j];
seg[o]=newo;
}
void down(int o){
zotfn(SEG_L,seg[o].lazy);
zotfn(SEG_R,seg[o].lazy);
seg[o].lazy={0,1,2};
}
Node query(int o,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr)return seg[o];
down(o);
Node resl = ql<=mid?query(SEG_L_CHILD,ql,qr):seg[0];
Node resr = qr> mid?query(SEG_R_CHILD,ql,qr):seg[0];
return merge(resl,resr);
}
void update(int o,int l,int r,int ql,int qr,const A3& zot){
if(ql<=l&&r<=qr) return zotfn(o,zot);
down(o);
if(ql<=mid) update(SEG_L_CHILD,ql,qr,zot);
if(qr> mid) update(SEG_R_CHILD,ql,qr,zot);
seg[o]=merge(seg[SEG_L],seg[SEG_R]);
}
int main(){
int n=read();
int q=read();
rep(i,0,n)a[i]=read();
build(SEG_ROOT);
while(q--){
int op=read();
int l=read()-1;
int r=read()-1;
if(op==1){
auto x=query(SEG_ROOT,l,r).c;
printf("%lld\n",x[1][0]+x[2][0]+x[2][1]);
}else{
A3 zot;
rep(i,0,3)zot[i]=read();
update(SEG_ROOT,l,r,zot);
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
G - 012 Inversion |
User |
cromarmot |
Language |
C++ (GCC 9.2.1) |
Score |
600 |
Code Size |
2099 Byte |
Status |
AC |
Exec Time |
392 ms |
Memory |
34944 KiB |
Compile Error
./Main.cpp: In function ‘ll read()’:
./Main.cpp:13:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
13 | ll read(){ll r;scanf("%lld",&r);return r;}
| ~~~~~^~~~~~~~~~~
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
600 / 600 |
Status |
|
|
Set Name |
Test Cases |
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 |
Case Name |
Status |
Exec Time |
Memory |
random_01.txt |
AC |
392 ms |
34876 KiB |
random_02.txt |
AC |
149 ms |
34824 KiB |
random_03.txt |
AC |
376 ms |
34840 KiB |
random_04.txt |
AC |
292 ms |
34776 KiB |
random_05.txt |
AC |
362 ms |
34704 KiB |
random_06.txt |
AC |
179 ms |
7472 KiB |
random_07.txt |
AC |
387 ms |
34840 KiB |
random_08.txt |
AC |
65 ms |
11456 KiB |
random_09.txt |
AC |
381 ms |
34844 KiB |
random_10.txt |
AC |
272 ms |
34772 KiB |
random_11.txt |
AC |
366 ms |
34836 KiB |
random_12.txt |
AC |
87 ms |
19092 KiB |
random_13.txt |
AC |
354 ms |
34724 KiB |
random_14.txt |
AC |
37 ms |
3900 KiB |
random_15.txt |
AC |
44 ms |
34776 KiB |
random_16.txt |
AC |
2 ms |
3656 KiB |
random_17.txt |
AC |
297 ms |
34756 KiB |
random_18.txt |
AC |
289 ms |
34888 KiB |
random_19.txt |
AC |
289 ms |
34856 KiB |
random_20.txt |
AC |
291 ms |
34944 KiB |
sample_01.txt |
AC |
4 ms |
3844 KiB |
sample_02.txt |
AC |
2 ms |
3648 KiB |