제출 #1166085

#제출 시각아이디문제언어결과실행 시간메모리
11660858pete8Fish 2 (JOI22_fish2)C++17
31 / 100
320 ms41552 KiB
#include<iostream> #include<stack> #include<map> #include<vector> #include<string> #include<cassert> #include<unordered_map> #include <queue> #include <cstdint> #include<cstring> #include<limits.h> #include<cmath> #include<set> #include<algorithm> #include <iomanip> #include<numeric> #include<bitset> using namespace std; #define ll long long #define f first #define s second #define pii pair<int,int> #define ppii pair<int,pii> #define vi vector<int> #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define F(n) for(int i=0;i<n;i++) #define lb lower_bound #define ub upper_bound #define fastio ios::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize ("03,unroll-lopps") #define int long long using namespace std; const int mod=1e9+7,mxn=2e5+5,inf=1e18,minf=-1e18,lg=30; //#undef int int n,k,m; int v[mxn+10],pref[mxn+10]; void setIO(string name){ ios_base::sync_with_stdio(0); cin.tie(0); freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } vector<int>L[mxn+10],R[mxn+10]; vector<pii>range; struct segmc{ int v[4*mxn+10],lazy[4*mxn+10],mn[4*mxn+10],mnc[4*mxn+19]; void pull(int pos){ v[pos]=v[pos<<1]+v[pos<<1|1]; if(mn[pos<<1]==mn[pos<<1|1]){ mn[pos]=mn[pos<<1]; mnc[pos]=mnc[pos<<1]+mnc[pos<<1|1]; } else{ if(mn[pos<<1]<mn[pos<<1|1]){ mn[pos]=mn[pos<<1]; mnc[pos]=mnc[pos<<1]; } else{ mn[pos]=mn[pos<<1|1]; mnc[pos]=mnc[pos<<1|1]; } } } void apply(int pos,int x,int l,int r){ v[pos]+=(r-l+1)*x; mn[pos]+=x; lazy[pos]+=x; } void push(int pos,int l,int r){ if(l!=r){ int mid=l+(r-l)/2; apply(pos<<1,lazy[pos],l,mid); apply(pos<<1|1,lazy[pos],mid+1,r); } lazy[pos]=0; } void build(int pos=1,int l=1,int r=n){ if(l==r)return void(mnc[pos]=1); int mid=l+(r-l)/2; build(pos<<1,l,mid); build(pos<<1|1,mid+1,r); pull(pos); } void updaterange(int ql,int qr,int x,int pos=1,int l=1,int r=n){ if(l>qr||r<ql)return; if(ql<=l&&r<=qr)return void(apply(pos,x,l,r)); int mid=l+(r-l)/2; push(pos,l,r); updaterange(ql,qr,x,pos<<1,l,mid); updaterange(ql,qr,x,pos<<1|1,mid+1,r); pull(pos); } pii qry(int ql,int qr,int pos=1,int l=1,int r=n){ if(l>qr||r<ql)return {inf,0}; if(ql<=l&&r<=qr){ return {mn[pos],mnc[pos]}; } int mid=l+(r-l)/2; push(pos,l,r); pii a=qry(ql,qr,pos<<1,l,mid); pii b=qry(ql,qr,pos<<1|1,mid+1,r); if(a.f==b.f)a.s+=b.s; else if(a.f>b.f)swap(a,b); pull(pos); return a; } }tc; struct segmn{ int lazy[4*mxn+10],mn[4*mxn+10]; void init(){for(int i=0;i<=4*n;i++)mn[i]=inf;} void pull(int pos){mn[pos]=min(mn[pos<<1],mn[pos<<1|1]);} void apply(int pos,int x,int l,int r){ mn[pos]+=x; lazy[pos]+=x; } void push(int pos,int l,int r){ if(l!=r){ int mid=l+(r-l)/2; apply(pos<<1,lazy[pos],l,mid); apply(pos<<1|1,lazy[pos],mid+1,r); } lazy[pos]=0; } void updaterange(int ql,int qr,int x,int pos=1,int l=1,int r=n){ if(l>qr||r<ql)return; if(ql<=l&&r<=qr)return void(apply(pos,x,l,r)); int mid=l+(r-l)/2; push(pos,l,r); updaterange(ql,qr,x,pos<<1,l,mid); updaterange(ql,qr,x,pos<<1|1,mid+1,r); pull(pos); } void updatepos(int qpos,int x,int pos=1,int l=1,int r=n){ if(l>qpos||r<qpos)return; if(l==r)return void(mn[pos]=x); int mid=l+(r-l)/2; push(pos,l,r); updatepos(qpos,x,pos<<1,l,mid); updatepos(qpos,x,pos<<1|1,mid+1,r); pull(pos); } int find_R(int ql,int qr,int x,int pos=1,int l=1,int r=n){ if(l>qr||r<ql)return minf; int mid=l+(r-l)/2; if(ql<=l&&r<=qr){ if(l==r)return ((mn[pos]<x)?l:minf); if(mn[pos<<1|1]<x)return find_R(ql,qr,x,pos<<1|1,mid+1,r); else return find_R(ql,qr,x,pos<<1,l,mid); } push(pos,l,r); int a=(find_R(ql,qr,x,pos<<1|1,mid+1,r)); if(a!=minf)return a; return find_R(ql,qr,x,pos<<1,l,mid); } }tmn; struct segmx{ int lazy[4*mxn+10],mx[4*mxn+10]; void init(){for(int i=0;i<=4*n;i++)mx[i]=minf;} void pull(int pos){mx[pos]=max(mx[pos<<1],mx[pos<<1|1]);} void apply(int pos,int x,int l,int r){ mx[pos]+=x; lazy[pos]+=x; } void push(int pos,int l,int r){ if(l!=r){ int mid=l+(r-l)/2; apply(pos<<1,lazy[pos],l,mid); apply(pos<<1|1,lazy[pos],mid+1,r); } lazy[pos]=0; } void updaterange(int ql,int qr,int x,int pos=1,int l=1,int r=n){ if(l>qr||r<ql)return; if(ql<=l&&r<=qr)return void(apply(pos,x,l,r)); int mid=l+(r-l)/2; push(pos,l,r); updaterange(ql,qr,x,pos<<1,l,mid); updaterange(ql,qr,x,pos<<1|1,mid+1,r); pull(pos); } void updatepos(int qpos,int x,int pos=1,int l=1,int r=n){ if(l>qpos||r<qpos)return; if(l==r)return void(mx[pos]=x); int mid=l+(r-l)/2; push(pos,l,r); updatepos(qpos,x,pos<<1,l,mid); updatepos(qpos,x,pos<<1|1,mid+1,r); pull(pos); } int qry(int ql,int qr,int pos=1,int l=1,int r=n){ if(l>qr||r<ql)return minf; if(ql<=l&&r<=qr)return mx[pos]; int mid=l+(r-l)/2; push(pos,l,r); return max(qry(ql,qr,pos<<1,l,mid),qry(ql,qr,pos<<1|1,mid+1,r)); } int find_L(int ql,int qr,int x,int pos=1,int l=1,int r=n){ if(l>qr||r<ql)return inf; int mid=l+(r-l)/2; if(ql<=l&&r<=qr){ if(l==r)return (mx[pos]>x)?l:inf; if(mx[pos<<1]>x)return find_L(ql,qr,x,pos<<1,l,mid); else return find_L(ql,qr,x,pos<<1|1,mid+1,r); } push(pos,l,r); int a=find_L(ql,qr,x,pos<<1,l,mid); if(a!=inf)return a; return find_L(ql,qr,x,pos<<1|1,mid+1,r); } }tmx; void init(){ stack<int>st; tmx.init(); tmn.init(); tc.build(); for(int i=1;i<=n;i++){ pref[i]=v[i]+pref[i-1]; tmn.updatepos(i,pref[i-1]-v[i]); tmx.updatepos(i,v[i]+pref[i]); while(!st.empty()&&v[i]>v[st.top()])st.pop(); if(st.size()&&pref[i-1]-pref[st.top()]<v[i])range.pb({st.top(),i}); st.push(i); } while(!st.empty())st.pop(); for(int i=n;i>=1;i--){ while(!st.empty()&&v[i]>v[st.top()])st.pop(); if(st.size()&&pref[st.top()-1]-pref[i]<v[i])range.pb({i,st.top()}); st.push(i); } for(auto i:range){ L[i.f].pb(i.s),R[i.s].pb(i.f); tc.updaterange(i.f+1,i.s-1,1); } } void solve(int l,int r){ int i=max(l,tmn.find_R(l,r,pref[l-1])); int j=min(r,tmx.find_L(l,r,pref[r])); cout<<tc.qry(i,j).s<<'\n'; } int32_t main(){ fastio //case so update cin>>n; for(int i=1;i<=n;i++)cin>>v[i]; init(); int q;cin>>q; while(q--){ int t,x,y;cin>>t>>x>>y; if(t==1){ assert(0); v[x]=y; } else solve(x,y); } } /* 5 6 4 2 2 6 1 2 1 3 2 1 3 */

컴파일 시 표준 에러 (stderr) 메시지

fish2.cpp:32:40: warning: bad option '-funroll-lopps' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize ("03,unroll-lopps")
      |                                        ^
fish2.cpp:39:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   39 | void setIO(string name){
      |                       ^
fish2.cpp:49:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   49 |     void pull(int pos){
      |                      ^
fish2.cpp:66:41: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   66 |     void apply(int pos,int x,int l,int r){
      |                                         ^
fish2.cpp:71:34: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   71 |     void push(int pos,int l,int r){
      |                                  ^
fish2.cpp:79:41: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   79 |     void build(int pos=1,int l=1,int r=n){
      |                                         ^
fish2.cpp:86:67: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   86 |     void updaterange(int ql,int qr,int x,int pos=1,int l=1,int r=n){
      |                                                                   ^
fish2.cpp:95:52: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
   95 |     pii qry(int ql,int qr,int pos=1,int l=1,int r=n){
      |                                                    ^
fish2.cpp:113:15: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  113 |     void init(){for(int i=0;i<=4*n;i++)mn[i]=inf;}
      |               ^
fish2.cpp:114:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  114 |     void pull(int pos){mn[pos]=min(mn[pos<<1],mn[pos<<1|1]);}
      |                      ^
fish2.cpp:115:41: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  115 |     void apply(int pos,int x,int l,int r){
      |                                         ^
fish2.cpp:119:34: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  119 |     void push(int pos,int l,int r){
      |                                  ^
fish2.cpp:127:67: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  127 |     void updaterange(int ql,int qr,int x,int pos=1,int l=1,int r=n){
      |                                                                   ^
fish2.cpp:136:60: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  136 |     void updatepos(int qpos,int x,int pos=1,int l=1,int r=n){
      |                                                            ^
fish2.cpp:145:61: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  145 |     int find_R(int ql,int qr,int x,int pos=1,int l=1,int r=n){
      |                                                             ^
fish2.cpp:163:15: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  163 |     void init(){for(int i=0;i<=4*n;i++)mx[i]=minf;}
      |               ^
fish2.cpp:164:22: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  164 |     void pull(int pos){mx[pos]=max(mx[pos<<1],mx[pos<<1|1]);}
      |                      ^
fish2.cpp:165:41: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  165 |     void apply(int pos,int x,int l,int r){
      |                                         ^
fish2.cpp:169:34: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  169 |     void push(int pos,int l,int r){
      |                                  ^
fish2.cpp:177:67: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  177 |     void updaterange(int ql,int qr,int x,int pos=1,int l=1,int r=n){
      |                                                                   ^
fish2.cpp:186:60: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  186 |     void updatepos(int qpos,int x,int pos=1,int l=1,int r=n){
      |                                                            ^
fish2.cpp:195:52: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  195 |     int qry(int ql,int qr,int pos=1,int l=1,int r=n){
      |                                                    ^
fish2.cpp:202:61: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  202 |     int find_L(int ql,int qr,int x,int pos=1,int l=1,int r=n){
      |                                                             ^
fish2.cpp:218:11: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  218 | void init(){
      |           ^
fish2.cpp:242:23: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  242 | void solve(int l,int r){
      |                       ^
fish2.cpp:247:14: warning: bad option '-funroll-lopps' to attribute 'optimize' [-Wattributes]
  247 | int32_t main(){
      |              ^
fish2.cpp: In function 'void setIO(std::string)':
fish2.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen((name+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fish2.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen((name+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...