제출 #987107

#제출 시각아이디문제언어결과실행 시간메모리
987107cpdreamerSjeckanje (COCI21_sjeckanje)C++14
0 / 110
2 ms348 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set; const int max_n=INT_MAX; typedef long long ll; #define pb push_back #define F first #define S second #define all(v) v.begin(),v.end() #define P pair #define V vector const long long MOD = 1000000007; // 1e9 + 7 void file(){ freopen("input.txt.txt","r",stdin); freopen("output.txt.txt","w",stdout); } void setio(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } struct station{ int p; int c; int l; int r; }; bool custom(station a,station b) { return a.p < b.p; } struct segtree{ private: struct node{ int maximum_value; int last_min; int last_max; int first_min; int first_max; bool divided; }; node neutral{-1,0,0,0,0,false}; static node single( int a) { return {0,a,a,a,a,false}; } static node merge(node a,node b){ if(b.maximum_value==-1) return a; if(a.maximum_value==-1) return b; node c{}; c.divided=false; c.maximum_value=a.maximum_value+b.maximum_value-(a.last_max-a.last_min)-(b.first_max-b.first_min); if(((a.last_max-a.last_min)+(b.first_max-b.first_min))>=(max(a.last_max,b.first_max)-min(a.last_min,b.first_min))){ c.maximum_value+=(a.last_max-a.last_min)+(b.first_max-b.first_min); c.divided=true; } else{ c.maximum_value+=(max(a.last_max,b.first_max)-min(a.last_min,b.first_min)); } if(c.divided){ c.first_max=a.first_max; c.first_min=a.first_min; c.last_min=b.last_min; c.last_max=b.last_max; } else{ if(a.divided){ c.first_max=a.first_max; c.first_min=a.first_min; } else{ c.first_max=max(a.first_max,b.first_max); c.first_min=min(a.first_min,b.first_min); } if(b.divided) { c.last_min = b.last_min; c.last_max = b.last_max; } else{ c.last_min=min(b.last_min,a.last_min); c.last_max=max(b.last_max,a.last_max); } } c.divided=a.divided||b.divided; return c; } public: int size; V<node>query; void init(int n){ size=1; while(size<n)size*=2; query.assign(2*size,{0}); } void build(V<int>&a,int x,int lx,int rx){ if(rx-lx==1){ if(lx<a.size()) query[x]=single(a[lx]); return; } int m=(lx+rx)/2; build(a,2*x+1,lx,m); build(a,2*x+2,m,rx); query[x]=merge(query[2*x+1],query[2*x+2]); } void build(V<int>&a){ build(a,0,0,size); } void set(int i,int v,int x,int lx,int rx){ if(rx-lx==1){ query[x]=single(v); return; } int m=(lx+rx)/2; if(i<m) set(i,v,2*x+1,lx,m); else set(i,v,2*x+2,m,rx); query[x]=merge(query[2*x+1],query[2*x+2]); } void set(int i,int v){ set(i,v,0,0,size); } int calc(){ return query[0].maximum_value; } }; void solve(){ int n; cin>>n; int q; cin>>q; V<int>a(n); for(int i=0;i<n;i++) cin>>a[i]; segtree tree; tree.init(n); tree.build(a); while(q--){ int l,r,v; cin>>l>>r>>v; for(int i=l-1;i<r;i++){ a[i]+=v; tree.set(i,a[i]); } cout<<tree.calc()<<endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // file(); solve(); return 0; }

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

Main.cpp: In member function 'void segtree::build(std::vector<int>&, int, int, int)':
Main.cpp:102:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |             if(lx<a.size())
      |                ~~^~~~~~~~~
Main.cpp: In function 'void file()':
Main.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen("input.txt.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen("output.txt.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void setio(std::string)':
Main.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...