Submission #997276

# Submission time Handle Problem Language Result Execution time Memory
997276 2024-06-12T00:58:53 Z JuanJL Monkey and Apple-trees (IZhO12_apple) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

#define fst first 
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i < b; i++)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(v) cout<<"Line("<<__LINE__<<"): "<<#v<<" = "<<v<<'\n';
#define pi pair<int,int>
#define pll pair<ll,ll>
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;

struct Node{
	ll val, l,r;
	Node(){ val=0;  l = r = -1; }
};

struct STree { // example: range sum with range addition
	int indice = 1;
	vector<Node> st,
	vector<int> lazy;int n;
	int M;
	STree(int n, int m): M(m), st(4*n+5,Node()), lazy(4*n+5,0), n(n) {}

	void push(int k, int s, int e){
		if(!lazy[k])return; // if neutral, nothing to do
		st[k].val=(e-s)*lazy[k]; // update st according to lazy
		if(s+1<e){ // propagate to children
			if(st[k].l==-1) st[k].l=indice,indice++;
			if(st[k].r==-1) st[k].r=indice,indice++;
			lazy[st[k.l]]=lazy[k];
			lazy[st[k].r]=lazy[k];
		}
		lazy[k]=0; // clear node lazy
	}
	void upd(int k, int s, int e, int a, int b, int v){
		push(k,s,e);
		if(s>=b||e<=a)return;
		if(s>=a&&e<=b){
			lazy[k]=v; // accumulate lazy
			push(k,s,e);return;
		}
		int m=(s+e)/2;
		if(st[k].l==-1) st[k].l=indice,indice++;
		if(st[k].r==-1) st[k].r=indice,indice++;
		upd(st[k].l,s,m,a,b,v);upd(st[k].r,m,e,a,b,v);
		st[k].val=st[st[k].l].val+st[st[k].r].val; // operation
	}
	int query(int k, int s, int e, int a, int b){
		if(s>=b||e<=a)return 0; // operation neutral
		push(k,s,e);
		if(s>=a&&e<=b)return st[k].val;
		int m=(s+e)/2;
		if(st[k].l==-1) st[k].l=indice,indice++;
		if(st[k].r==-1) st[k].r=indice,indice++;
		return query(st[k].l,s,m,a,b)+query(st[k].r,m,e,a,b); // operation
	}
	
	void upd(int a, int b, int v){upd(1,0,M,a,b,v);}
	int query(int a, int b){return query(1,0,M,a,b);}
};

int main(){FIN;
	ll m; cin>>m;
	ll t,c,pC; c=0;
	ll l,r;
	STree stree(100000+5,1000000000+5);
	
	while(m--){
		cin>>t>>l>>r;
		
		/*if(c+r+1>=1000000+2){
			while(true){}
		}*/
		
		if(t==2){
			stree.upd(c+l,c+r+1,1);
		}else{
			//cout<<"QUERY\n";
			pC=stree.query(l+c,r+c+1);
			cout<<pC<<'\n';
			c=pC;
		}
	}
	return 0;
}

Compilation message

apple.cpp:30:14: error: invalid declarator before 'lazy'
   30 |  vector<int> lazy;int n;
      |              ^~~~
apple.cpp: In constructor 'STree::STree(int, int)':
apple.cpp:32:47: error: class 'STree' does not have any field named 'lazy'
   32 |  STree(int n, int m): M(m), st(4*n+5,Node()), lazy(4*n+5,0), n(n) {}
      |                                               ^~~~
apple.cpp:31:6: warning: 'STree::M' will be initialized after [-Wreorder]
   31 |  int M;
      |      ^
apple.cpp:29:15: warning:   'std::vector<Node> STree::st' [-Wreorder]
   29 |  vector<Node> st,
      |               ^~
apple.cpp:32:2: warning:   when initialized here [-Wreorder]
   32 |  STree(int n, int m): M(m), st(4*n+5,Node()), lazy(4*n+5,0), n(n) {}
      |  ^~~~~
apple.cpp: In member function 'void STree::push(int, int, int)':
apple.cpp:35:7: error: 'lazy' was not declared in this scope
   35 |   if(!lazy[k])return; // if neutral, nothing to do
      |       ^~~~
apple.cpp:36:19: error: 'lazy' was not declared in this scope
   36 |   st[k].val=(e-s)*lazy[k]; // update st according to lazy
      |                   ^~~~
apple.cpp:40:14: error: request for member 'l' in 'k', which is of non-class type 'int'
   40 |    lazy[st[k.l]]=lazy[k];
      |              ^
apple.cpp: In member function 'void STree::upd(int, int, int, int, int, int)':
apple.cpp:49:4: error: 'lazy' was not declared in this scope
   49 |    lazy[k]=v; // accumulate lazy
      |    ^~~~