QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#360851 | #8229. 栈 | zzafanti | 0 | 288ms | 43008kb | C++23 | 3.3kb | 2024-03-22 11:51:18 | 2024-03-22 11:51:19 |
Judging History
answer
#ifdef zzafanti
#define _GLIBCXX_DEBUG
#endif // zzafanti
#include<bits/stdc++.h>
using namespace std;
using E=long long;
E sgn(E x){ return x<0?-1:1; }
struct segment{
struct node{
int l,r;
E x,lsum,y,val;
node(){
l=r=0;
x=y=val=lsum=0;
}
};
/**
* add ()
* query ()
*/
vector<node> tr,mem;
void build(int u,int l,int r){
tr[u].l=l,tr[u].r=r;
if(l==r) return ;
int mid=(l+r)>>1;
build(u<<1,l,mid),build(u<<1|1,mid+1,r);
}
segment(int sz){
mem=tr=vector<node>(sz*4+12);
if(sz>=1) build(1,1,sz);
}
E calcu(int u,E k){ /// sum of the first k '('
int l=tr[u].l,r=tr[u].r;
if(l==r) return (tr[u].val)*k;
int mid=(l+r)>>1;
if(tr[u<<1].x-tr[u<<1|1].y>=k) return calcu(u<<1,k);
return calcu(u<<1|1,k-max(0ll,(tr[u<<1].x-tr[u<<1|1].y)))+tr[u].lsum;
}
void maintain(vector<node> &Tr,int u){
int ls=u<<1,rs=u<<1|1;
if(Tr[rs].y>=Tr[ls].x){
Tr[u].y=Tr[ls].y+Tr[rs].y-Tr[ls].x;
Tr[u].x=Tr[rs].x;
return ;
}
Tr[u].lsum=calcu(u<<1,Tr[ls].x-Tr[rs].y);
Tr[u].x=Tr[rs].x+Tr[ls].x-Tr[rs].y;
Tr[u].y=Tr[ls].y;
}
void add(int u,int pos,E dx,E ds,E dy){
int l=tr[u].l,r=tr[u].r;
if(l==r){
tr[u].x+=dx;
tr[u].val+=ds;
tr[u].y+=dy;
return ;
}
int mid=(l+r)>>1;
if(pos<=mid) add(u<<1,pos,dx,ds,dy);
else add(u<<1|1,pos,dx,ds,dy);
maintain(tr,u);
}
E query(int u,int R,E k){
int l=tr[u].l,r=tr[u].r;
if(r<=R){
mem[u]=tr[u];
return calcu(u,k);
}
int mid=(l+r)>>1;
if(R<=mid){
auto T=query(u<<1,R,k);
maintain(mem,u);
return T;
}
query(u<<1,R,k);
query(u<<1|1,R,k);
maintain(mem,u);
return calcu(u,k);
}
};
constexpr int N=100010;
struct querys{
int op,when;
E l,r;
querys() { op=l=when=r=0; }
querys(int Op=0,int wh=0,E L=0,E R=0) { op=Op,when=wh,l=L,r=R; }
friend bool operator < (const querys &x,const querys &y){
return x.when<y.when;
}
};
vector<querys> oper[N];
int n,m;
int main(){
#ifdef zzafanti
freopen("in.in","r",stdin);
#endif // zzafanti
cin.tie(nullptr),cout.tie(nullptr)->sync_with_stdio(false);
cin>>n>>m;
vector<E> ans(m+1,-1);
for(int i=1; i<=m; i++){
int op,l,r;
E x,y;
cin>>op;
if(op==1){
cin>>l>>r>>x>>y;
oper[l].emplace_back(querys(1,i,x,y));
if(r<n) oper[r+1].emplace_back(querys(-1,i,x,y));
}
if(op==2){
cin>>l>>r>>x;
oper[l].emplace_back(querys(2,i,x,0));
if(r<n) oper[r+1].emplace_back(querys(-2,i,x,0));
}
if(op==3){
cin>>l>>x>>y;
oper[l].emplace_back(querys(3,i,x,y));
}
}
segment S(m);
for(int i=1; i<=n; i++){
sort(oper[i].begin(),oper[i].end());
for(auto pt:oper[i]){
if(abs(pt.op)==1){
S.add(1,pt.when,pt.l*sgn(pt.op),sgn(pt.op)*pt.r,0);
}
if(abs(pt.op)==2){
S.add(1,pt.when,0,0,pt.l*sgn(pt.op));
}
if(pt.op==3){
ans[pt.when]=S.query(1,pt.when,pt.r)-S.query(1,pt.when,pt.l-1);
}
}
}
for(int i=1; i<=m; i++){
if(ans[i]!=-1){
cout<<ans[i]<<'\n';
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 5100kb
input:
4907 4910 2 763 3330 1 3 307 1 1 1 2262 3430 22699 89397 1 1915 4000 51541 67587 2 212 2990 9763 2 1086 2162 1 2 1813 4496 16760 1 51 2796 68005 99390 1 1267 1519 74236 66178 3 1768 23808 54314 2 900 4122 27758 3 3287 17350 28989 2 3277 4024 3633 2 444 4866 1 2 353 4219 1061 1 987 3141 99906 17320 2...
output:
0 3032090730 2519753626 471569175 0 945105186 5066615631 123945 50793012 592881238 0 1081577601 16481339523 762429740 126631302 0 565608225 3072124281 1081577601 1792521566 23121783080 2415375780 249435711 225987900 5250788038 0 0 -1138880134 118545795 0 9853830085 0 0 0 12221814969 2647126197 -1138...
result:
wrong answer 3rd numbers differ - expected: '903396180', found: '2519753626'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 288ms
memory: 42476kb
input:
99999 99998 1 5026 18575 27178 90423 3 30623 1 1 3 76936 1 1 1 77021 95683 84664 24734 1 46085 74886 40512 11266 3 5048 8594 22468 1 53318 77721 97151 70784 1 70645 91192 37556 13013 1 56752 56940 91812 62887 1 7928 34576 87339 69404 3 74875 32807 100970 3 22338 17221 25771 3 21421 20602 57957 3 717...
output:
2457516294 2457516294 1254619125 4366274868 593473604 2592655824 3657975552 5652513833 110091352 1226646296 1989326852 763582808 20410671941 1659086055 3012598941 20085582585 15350314335 33063695949 28572771569 4722824224 27067502374 899316516 49569427017 988382364 13341823621 11397759491 2449683584...
result:
wrong answer 1st numbers differ - expected: '0', found: '2457516294'
Subtask #3:
score: 0
Wrong Answer
Test #12:
score: 0
Wrong Answer
time: 149ms
memory: 43008kb
input:
100000 99993 1 47773 70467 16065 1 2 52349 78446 2304 3 40821 1 1 1 40216 93069 78144 1 1 41089 43671 76025 1 2 35263 68629 31066 3 79881 13534 57327 3 5556 1 1 2 21962 38192 1 1 664 58116 9417 1 3 28089 6039 7989 2 88500 90302 9946 3 63215 49410 60770 2 11069 89527 57581 2 70303 97603 12363 1 3420 ...
output:
1 43794 1 1951 11361 0 0 29245 7969 1947 34972 16405 102386 211244 38615 110643 48615 1 0 37527 1 31810 16824 96178 14285 594967 0 0 0 0 0 0 0 0 26099 28608 250368 0 183349 125791 0 0 42058 56549 2698 183297 0 54464 0 26259 358182 254217 40448 40448 18437 0 108 1 138046 0 406480 0 118370 0 0 0 0 0 0...
result:
wrong answer 1st numbers differ - expected: '0', found: '1'
Subtask #4:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 152ms
memory: 42976kb
input:
99999 99996 3 77889 1 10000000000 1 6316 86327 89644 386 3 9260 1 10000000000 2 2603 47234 69717 2 20260 73011 19290 2 62477 81233 26127 1 50140 68508 37004 98794 2 14449 22788 16063 1 43860 84932 50375 21777 1 67345 94584 28202 66610 2 661 68654 1 1 14411 94422 82738 61196 1 16563 94416 4920 38408 ...
output:
0 7691822 753026142057471 39338645991335 35864198151 -561231032 39330000000000 6854971767 1843770600 12363481960 1867899555 15512077952 5676974753 5676974753 16173399833 13517842793 5676974753 19357850696 4141902439 1843770600 0 12604167463 14432325689 11489314040 6874676097 0 0 0 0 28338278352 0 35...
result:
wrong answer 2nd numbers differ - expected: '34602584', found: '7691822'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%