Submission #69859706
Source Code Expand
#include<bits/stdc++.h>
//bool Mst;
using namespace std;
namespace wyzfastio
{
const char bool_str[2][6]={"false","true"};const int double_mx=12;
#define usefio
#ifdef usefio
namespace __getchar{const int bufsize=1<<22;char buf[bufsize],*p1=buf,*p2=buf;inline char getchar(){return (p1==p2&&(p2=(p1=buf)+fread(buf,1,bufsize,stdin),p1==p2))?EOF:(*p1++);}}using __getchar::getchar;
namespace __putchar{const int bufsize=1<<22;char buf[bufsize],*p=buf;inline void putchar(const char ch){if(p-buf==bufsize) fwrite(buf,1,bufsize,stdout),p=buf;*p++=ch;}inline void flush(){fwrite(buf,1,p-buf,stdout);}}using __putchar::putchar;using __putchar::flush;
namespace __flusher{struct Flusher{Flusher(){}~Flusher(){flush();}}flusher;}
#endif
struct istream{void tie([[maybe_unused]]int x){}};struct ostream{void tie([[maybe_unused]]int x){}};struct estream{};istream in;ostream out;
#ifdef LOCAL
ostream err;
#else
estream err;
#endif
istream &operator>>(istream &in,char &s){s=getchar();while(s==' '||s=='\n'||s=='\r')s=getchar();return in;}
istream &operator>>(istream &in,std::string &s){char ch=getchar();s.clear();while(ch==' '||ch=='\n'||ch=='\r')ch=getchar();while(!(ch==' '||ch=='\n'||ch=='\r'||ch==EOF))s+=ch,ch=getchar();return in;}
istream &operator>>(istream &in,__int128 &x){char ch=getchar();int o=0;__int128 r=0;while(ch<'0'||ch>'9'){if(ch=='-')o^=1;ch=getchar();}while(ch>='0'&&ch<='9')r=(r<<3)+(r<<1)+ch-'0',ch=getchar();x=o?-r:r;return in;}
istream &operator>>(istream &in,unsigned __int128 &x){char ch=getchar();__int128 r=0;while(ch>='0'&&ch<='9')r=(r<<3)+(r<<1)+ch-'0',ch=getchar();x=r;return in;}
template<typename _Tp>inline typename std::enable_if<std::is_integral<_Tp>::value&&!std::is_same<_Tp,bool>::value,istream &>::type operator>>(istream &in,_Tp &x){char ch=getchar();int o=0;_Tp r=0;while(ch<'0'||ch>'9'){if(ch=='-')o^=1;ch=getchar();}while(ch>='0'&&ch<='9')r=(r<<3)+(r<<1)+ch-'0',ch=getchar();x=o?-r:r;return in;}
template<typename _Tp>inline typename std::enable_if<std::is_same<_Tp,bool>::value,istream &>::type operator>>(istream &in,_Tp &x){int r;in>>r;x=r;}
template<typename _Tp>inline typename std::enable_if<std::is_floating_point<_Tp>::value,istream &>::type operator>>(istream &in,_Tp &x){_Tp r=0,p=1;int op=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')op=-op;ch=getchar();}while(ch>='0'&&ch<='9'){r=r*10+ch-'0';ch=getchar();}if(ch=='.'){ch=getchar();while(ch>='0'&&ch<='9')r+=(p*=0.1)*(ch-'0'),ch=getchar();}x=r*op;return in;}
ostream &operator<<(ostream &out,const char x){putchar(x);return out;}
ostream &operator<<(ostream &out,const char *s){while(*s!='\0'&&*s!=EOF)putchar(*s),s++;return out;}
ostream &operator<<(ostream &out,std::string s){for(char ch:s)putchar(ch);return out;}
ostream &operator<<(ostream &out,__int128 x){static int __stk[66];int top=0,op=1-((x<0)<<1);if(x==0)__stk[top++]=0;else while(x)__stk[top++]=(x%10)*op,x/=10;if(op==-1)putchar('-');while(top)putchar(__stk[--top]+'0');return out;}
ostream &operator<<(ostream &out,unsigned __int128 x){static int __stk[66];int top=0;if(x==0)__stk[top++]=0;else while(x)__stk[top++]=(x%10),x/=10;while(top)putchar(__stk[--top]+'0');return out;}
template<typename _Tp>inline typename std::enable_if<std::is_integral<_Tp>::value&&!std::is_same<_Tp,bool>::value,ostream &>::type operator<<(ostream &out,_Tp x){static int __stk[33];int top=0,op=1-((x<0)<<1);if(x==0)__stk[top++]=0;else while(x)__stk[top++]=(x%10)*op,x/=10;if(op==-1)putchar('-');while(top)putchar(__stk[--top]+'0');return out;}
template<typename _Tp>inline typename std::enable_if<std::is_same<_Tp,bool>::value,ostream &>::type operator<<(ostream &out,_Tp x){out<<bool_str[x];return out;}
template<typename _Tp>inline typename std::enable_if<std::is_floating_point<_Tp>::value,ostream &>::type operator<<(ostream &out,_Tp x){if(x<0)putchar('-'),x=-x;static int __stk[233];int top=0;for(int i=0;i<double_mx;i++)x*=10;x=std::floor(x+0.5);for(_Tp y;x>=1;)y=std::floor(x/10),__stk[top++]=x-y*10,x=y;while(top<=double_mx)__stk[top++]=0;while(top>double_mx)putchar(__stk[--top]+'0');putchar('.');while(top)putchar(__stk[--top]+'0');return out;}
template<typename _Tp>inline estream &operator<<(estream &err,[[maybe_unused]]_Tp x){return err;}
#define cin wyzfastio::in
#define cout wyzfastio::out
#define cerr wyzfastio::err
}
using ll=long long;
using ld=long double;
#define int ll
using pii=pair<int,int>;
const int N=3e5+5;
int t[N<<2],mn[N<<2],mx[N<<2],tag[N<<2];
inline int ls(int id){return id<<1;}
inline int rs(int id){return id<<1|1;}
inline void push_up(int id)
{
t[id]=t[ls(id)]+t[rs(id)];
mn[id]=min(mn[ls(id)],mn[rs(id)]);
mx[id]=max(mx[ls(id)],mx[rs(id)]);
}
inline void upd(int x,int id,int nl,int nr);
inline void push_down(int id,int nl,int nr)
{
if(!tag[id]) return;
int m=(nl+nr)>>1;
upd(tag[id],ls(id),nl,m);
upd(tag[id],rs(id),m+1,nr);
tag[id]=0;
}
inline void upd(int x,int id,int nl,int nr)
{
if(!mx[id]) return;
if(nl==nr)
{
x=min(x,t[id]);
t[id]-=x,mn[id]=mx[id]=x;
return;
}
if(mn[id]>=x)
{
tag[id]+=x,t[id]-=x*(nr-nl+1),mn[id]-=x,mx[id]-=x;
return;
}
push_down(id,nl,nr);
int m=(nl+nr)>>1;
upd(x,ls(id),nl,m),upd(x,rs(id),m+1,nr);
push_up(id);
}
inline void update(int l,int r,int x,int id,int nl,int nr)
{
if(l<=nl&&r>=nr) return upd(x,id,nl,nr),void();
push_down(id,nl,nr);
int m=(nl+nr)>>1;
if(l<=m) update(l,r,x,ls(id),nl,m);
if(r>m) update(l,r,x,rs(id),m+1,nr);
push_up(id);
}
int a[N];
inline void build(int id,int nl,int nr)
{
if(nl==nr) return t[id]=mn[id]=mx[id]=a[nl],void();
int m=(nl+nr)>>1;
build(ls(id),nl,m),build(rs(id),m+1,nr);
push_up(id);
}
//bool Med;
signed main()
{
// cerr<<"Memory Size: "<<abs((&Med)-(&Mst))/1024.0/1024<<" MB\n";
// freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
int n,q;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
build(1,1,n);
int lst=t[1];
cin>>q;
while(q--)
{
int l,r,k;
cin>>l>>r>>k;
update(l,r,k,1,1,n);
int cur=t[1];
cout<<lst-cur<<"\n";
lst=cur;
}
return 0;
}
Submission Info
| Submission Time |
|
| Task |
F - Clearance |
| User |
wangyizhi |
| Language |
C++ 20 (gcc 12.2) |
| Score |
0 |
| Code Size |
6115 Byte |
| Status |
WA |
| Exec Time |
5523 ms |
| Memory |
43484 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
0 / 525 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
sample_01.txt |
| All |
sample_01.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt |
| Case Name |
Status |
Exec Time |
Memory |
| sample_01.txt |
AC |
1 ms |
3532 KiB |
| test_01.txt |
AC |
1 ms |
3520 KiB |
| test_02.txt |
AC |
1 ms |
3380 KiB |
| test_03.txt |
AC |
1 ms |
3400 KiB |
| test_04.txt |
AC |
19 ms |
11128 KiB |
| test_05.txt |
AC |
14 ms |
9484 KiB |
| test_06.txt |
AC |
10 ms |
8600 KiB |
| test_07.txt |
TLE |
5519 ms |
38364 KiB |
| test_08.txt |
WA |
3056 ms |
39320 KiB |
| test_09.txt |
WA |
1424 ms |
39292 KiB |
| test_10.txt |
TLE |
5520 ms |
38544 KiB |
| test_11.txt |
TLE |
5519 ms |
38440 KiB |
| test_12.txt |
TLE |
5519 ms |
38436 KiB |
| test_13.txt |
TLE |
5519 ms |
38560 KiB |
| test_14.txt |
TLE |
5519 ms |
38552 KiB |
| test_15.txt |
TLE |
5522 ms |
38584 KiB |
| test_16.txt |
TLE |
5519 ms |
38356 KiB |
| test_17.txt |
TLE |
5517 ms |
38320 KiB |
| test_18.txt |
TLE |
5516 ms |
38288 KiB |
| test_19.txt |
TLE |
5523 ms |
38448 KiB |
| test_20.txt |
TLE |
5522 ms |
38328 KiB |
| test_21.txt |
TLE |
5522 ms |
38288 KiB |
| test_22.txt |
TLE |
5520 ms |
38384 KiB |
| test_23.txt |
TLE |
5520 ms |
38384 KiB |
| test_24.txt |
TLE |
5520 ms |
38532 KiB |
| test_25.txt |
TLE |
5520 ms |
38336 KiB |
| test_26.txt |
TLE |
5520 ms |
35908 KiB |
| test_27.txt |
WA |
3946 ms |
43484 KiB |
| test_28.txt |
TLE |
5519 ms |
35320 KiB |
| test_29.txt |
TLE |
5519 ms |
35288 KiB |
| test_30.txt |
TLE |
5519 ms |
35620 KiB |
| test_31.txt |
TLE |
5519 ms |
35472 KiB |
| test_32.txt |
TLE |
5517 ms |
38552 KiB |
| test_33.txt |
TLE |
5520 ms |
38460 KiB |
| test_34.txt |
TLE |
5520 ms |
38604 KiB |
| test_35.txt |
TLE |
5520 ms |
38580 KiB |
| test_36.txt |
TLE |
5520 ms |
38572 KiB |
| test_37.txt |
TLE |
5520 ms |
38508 KiB |