QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#538051 | #8139. Ayano and sequences | Kostlin | WA | 1ms | 7948kb | C++14 | 3.8kb | 2024-08-30 21:51:25 | 2024-08-30 21:51:25 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#define pii pair<int,int>
#define fi first
#define sc second
#define mkp make_pair
using namespace std;
const int N=5e5+5;
int n,q,a[N];
unsigned long long b[N],bb[N];
set<pii> S;
set<pii>::iterator it,It;
inline int read() {
int x=0,fl=0;char ch=getchar();
while(ch<'0'||ch>'9') {fl|=(ch=='-'); ch=getchar();}
while('0'<=ch&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0'; ch=getchar();}
return fl?-x:x;
}
inline int mx(int x,int y) {return x>y?x:y;}
inline int mn(int x,int y) {return x<y?x:y;}
struct Sgt {
struct Node {
unsigned long long sm,tg;
bool Tg;
}w[N<<2];
inline void pu(int ht) {w[ht].sm=w[ht<<1].sm+w[ht<<1|1].sm;}
inline void pd(int ht,int ln,int rn) {
if(w[ht].Tg) {
w[ht<<1].Tg=1;
w[ht<<1].sm=w[ht<<1].tg=0;
w[ht<<1|1].Tg=1;
w[ht<<1|1].sm=w[ht<<1|1].tg=0;
w[ht].Tg=0;
}
if(w[ht].tg) {
w[ht<<1].tg+=w[ht].tg;
w[ht<<1].sm+=1ull*ln*w[ht].tg;
w[ht<<1|1].tg+=w[ht].tg;
w[ht<<1|1].sm+=1ull*rn*w[ht].tg;
w[ht].tg=0;
}
}
void update(int l,int r,int ht,int L,int R,unsigned long long qwq) {
if(L<=l&&r<=R) {
w[ht].sm+=1ull*(r-l+1)*qwq;
w[ht].tg+=qwq;
return ;
} int mid=(l+r)>>1; pd(ht,mid-l+1,r-mid);
if(L<=mid) update(l,mid,ht<<1,L,R,qwq);
if(R> mid) update(mid+1,r,ht<<1|1,L,R,qwq);
pu(ht);
}
void Update(int l,int r,int ht,int L,int R) {
if(L<=l&&r<=R) {
w[ht].Tg=1;
w[ht].sm=w[ht].tg=0;
return ;
} int mid=(l+r)>>1; pd(ht,mid-l+1,r-mid);
if(L<=mid) Update(l,mid,ht<<1,L,R);
if(R> mid) Update(mid+1,r,ht<<1|1,L,R);
pu(ht);
}
unsigned long long query(int l,int r,int ht,int L,int R) {
if(L<=l&&r<=R) return w[ht].sm;
int mid=(l+r)>>1; pd(ht,mid-l+1,r-mid);
if(L<=mid) {
if(R>mid) return query(l,mid,ht<<1,L,R)+query(mid+1,r,ht<<1|1,L,R);
else return query(l,mid,ht<<1,L,R);
} else return query(mid+1,r,ht<<1|1,L,R);
}
}w1,w2;
inline void prep() {
int l=1,r;
while(l<=n) {
r=l;while(r<=n&&a[r]==a[l])++r;--r;
S.insert(mkp(l,r));
l=r+1;
}
}
inline void Ins(int l,int r,int tm) {
bb[l]=1ull*tm*w1.query(1,n,1,l,r);
S.insert(mkp(l,r));
}
inline void Era(int l,int r,int tm) {
b[a[l]]+=(1ull*tm*w1.query(1,n,1,l,r)-bb[l]-w2.query(1,n,1,l,r));bb[l]=0;
w2.Update(1,n,1,l,r);
}
inline void work1(int l,int r,int p,int T) {
it=S.lower_bound(mkp(l,0));
if((*it).fi!=l) {
--it;
Era((*it).fi,(*it).sc,T);
Ins((*it).fi,l-1,T);
It=it; ++It; S.erase(it); it=It;
}
while(it!=S.end()&&(*it).sc<=r) {
Era((*it).fi,(*it).sc,T);
It=it; ++It; S.erase(it); it=It;
}
if(it!=S.end()&&(*it).fi<=r) {
Era((*it).fi,(*it).sc,T);
Ins(r+1,(*it).sc,T);
S.erase(it);
}
a[l]=p;Ins(l,r,T);
}
inline void work2(int l,int r,int p,int T) {
w1.update(1,n,1,l,r,1ull*p);
w2.update(1,n,1,l,r,1ull*T*p);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
n=read();q=read();
for(int i=1;i<=n;++i) a[i]=read();
prep();
for(int i=1,op,l,r,p;i<=q;++i) {
op=read();l=read();r=read();p=read();
if(op==1) work1(l,r,p,i);
else work2(l,r,p,i);
}
it=S.begin();
while(it!=S.end()) {
Era((*it).fi,(*it).sc,q+1);
It=it; ++It; S.erase(it); it=It;
}
for(int i=1;i<=n;++i) printf("%llu ",b[i]);
printf("\n");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7876kb
input:
5 6 1 2 3 4 5 2 2 4 1 1 2 3 3 2 3 4 3 1 3 5 4 2 1 5 2 1 1 3 2
output:
2 12 12 36 0
result:
ok single line: '2 12 12 36 0 '
Test #2:
score: 0
Accepted
time: 1ms
memory: 7884kb
input:
10 10 9 2 8 8 6 5 4 8 5 3 2 2 6 268792718 2 7 8 125908043 2 2 3 150414369 2 6 10 856168102 2 4 5 274667941 1 1 9 6 2 2 6 646837311 2 6 6 105650419 2 7 9 254786900 2 1 7 73936815
output:
0 1795206697 5993176714 2215968376 4768635998 46271691633 0 5629806604 0 0
result:
ok single line: '0 1795206697 5993176714 221596...8 46271691633 0 5629806604 0 0 '
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 7948kb
input:
100 100 59 96 34 48 8 72 67 90 15 85 7 90 97 47 25 44 69 6 86 32 57 47 21 9 63 10 75 35 61 11 75 100 50 53 15 40 35 86 97 77 27 30 35 91 72 87 56 25 95 70 60 22 47 49 68 61 35 87 16 54 20 91 35 39 64 21 58 44 5 20 61 87 66 74 45 64 9 84 1 26 32 63 53 33 96 47 73 94 45 32 99 14 44 48 1 78 7 10 68 52 ...
output:
30388074576 0 0 0 309880184 347085980 0 5208679581 0 0 1364108550248 462582810805 0 309880184 0 309880184 0 18446743949671646464 0 1470341419 1160461235 0 0 825012506496 1041257940 152107932130 0 951255722094 0 0 18446742548552561530 23117155178 683986398348 116732654801 1634455423812 0 0 1924396708...
result:
wrong answer 1st lines differ - expected: '274832111654 0 0 0 309880184 3...994 609693254112 307568016399 0', found: '30388074576 0 0 0 309880184 34...93 538192296146 432338977480 0 '