Submission #229535

# Submission time Handle Problem Language Result Execution time Memory
229535 2020-05-04T23:19:47 Z blacktulip Simple (info1cup19_simple) C++17
100 / 100
812 ms 46712 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define int long long
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
 
const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 200003;
const lo mod = 1000000007;
 
int n,m,b[li],a[li],k,flag,t,tree[li*4],tree1[li*4],lazy[li*4],lazy1[li*4],tree2[li*4],tree3[li*4],lazy2[li*4],lazy3[li*4],val;
int cev;
string s;
vector<int> v;
 
inline void build(int node,int start,int end){
	if(start>end)return ;
	if(start==end){tree[node]=a[start]*(a[start]%2==0?-1:1);return ;}
	build(node*2,start,mid),build(node*2+1,mid+1,end);
	tree[node]=max(tree[node*2],tree[node*2+1]);
}
 
inline void build1(int node,int start,int end){
	if(start>end)return ;
	if(start==end){tree1[node]=(a[start]%2==0?-a[start]:a[start]);return ;}
	build1(node*2,start,mid),build1(node*2+1,mid+1,end);
	tree1[node]=min(tree1[node*2],tree1[node*2+1]);
}

inline void push(int node,int start,int end){
	if(lazy[node]==0)return ;
	tree[node]+=lazy[node];
	tree1[node]-=lazy[node];
	if(lazy[node]%2!=0){
		//~ cout<<tree[node]<<"**\n";
		swap(tree[node],tree1[node]);
		tree[node]*=-1;
		tree1[node]*=-1;
	}
	if(start!=end){
		lazy[node*2]+=lazy[node];
		lazy[node*2+1]+=lazy[node];
		lazy1[node*2]+=lazy[node];
		lazy1[node*2+1]+=lazy[node];
	}
	lazy[node]=0;
	lazy1[node]=0;
}

inline void push1(int node,int start,int end){
	if(lazy1[node]==0)return ;
	tree[node]+=lazy1[node];
	tree1[node]-=lazy1[node];
	if(lazy1[node]%2!=0){
		swap(tree[node],tree1[node]);
		tree[node]*=-1;
		tree1[node]*=-1;
	}
	if(start!=end){
		lazy[node*2]+=lazy1[node];
		lazy[node*2+1]+=lazy1[node];
		lazy1[node*2]+=lazy1[node];
		lazy1[node*2+1]+=lazy1[node];
	}
	lazy[node]=0;
	lazy1[node]=0;
}

inline void update(int node,int start,int end,int l,int r){
	push(node,start,end);
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){lazy[node]+=val;lazy1[node]+=val;push(node,start,end);return;}
	update(node*2,start,mid,l,r),update(node*2+1,mid+1,end,l,r);
	tree[node]=max(tree[node*2],tree[node*2+1]);
}

inline void update1(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){return;}
	update1(node*2,start,mid,l,r),update1(node*2+1,mid+1,end,l,r);
	tree1[node]=min(tree1[node*2],tree1[node*2+1]);
}

inline int query(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return -inf;
	push(node,start,end);
	if(start>=l && end<=r){return tree[node];}
	return max(query(node*2,start,mid,l,r),query(node*2+1,mid+1,end,l,r));
}
 
inline int query1(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return inf;
	push1(node,start,end);
	if(start>=l && end<=r){return tree1[node];}
	return min(query1(node*2,start,mid,l,r),query1(node*2+1,mid+1,end,l,r));
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

inline void build2(int node,int start,int end){
	if(start>end)return ;
	if(start==end){tree2[node]=b[start]*(b[start]%2==0?-1:1);return ;}
	build2(node*2,start,mid),build2(node*2+1,mid+1,end);
	tree2[node]=max(tree2[node*2],tree2[node*2+1]);
}
 
inline void build3(int node,int start,int end){
	if(start>end)return ;
	if(start==end){tree3[node]=(b[start]%2==0?-b[start]:b[start]);return ;}
	build3(node*2,start,mid),build3(node*2+1,mid+1,end);
	tree3[node]=min(tree3[node*2],tree3[node*2+1]);
}

inline void push2(int node,int start,int end){
	if(lazy2[node]==0)return ;
	tree2[node]-=lazy2[node];
	tree3[node]+=lazy2[node];
	if(lazy2[node]%2!=0){
		//~ cout<<tree2[node]<<"**\n";
		swap(tree2[node],tree3[node]);
		tree2[node]*=-1;
		tree3[node]*=-1;
	}
	if(start!=end){
		lazy2[node*2]+=lazy2[node];
		lazy2[node*2+1]+=lazy2[node];
		lazy3[node*2]+=lazy2[node];
		lazy3[node*2+1]+=lazy2[node];
	}
	lazy2[node]=0;
	lazy3[node]=0;
}

inline void push3(int node,int start,int end){
	if(lazy3[node]==0)return ;
	tree2[node]-=lazy3[node];
	tree3[node]+=lazy3[node];
	if(lazy3[node]%2!=0 ){
		swap(tree2[node],tree3[node]);
		tree2[node]*=-1;
		tree3[node]*=-1;
	}
	if(start!=end){
		lazy2[node*2]+=lazy3[node];
		lazy2[node*2+1]+=lazy3[node];
		lazy3[node*2]+=lazy3[node];
		lazy3[node*2+1]+=lazy3[node];
	}
	lazy2[node]=0;
	lazy3[node]=0;
}

inline void update2(int node,int start,int end,int l,int r){
	push2(node,start,end);
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){lazy2[node]+=val;lazy3[node]+=val;push2(node,start,end);return;}
	update2(node*2,start,mid,l,r),update2(node*2+1,mid+1,end,l,r);
	tree2[node]=max(tree2[node*2],tree2[node*2+1]);
}

inline void update3(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){return;}
	update3(node*2,start,mid,l,r),update3(node*2+1,mid+1,end,l,r);
	tree3[node]=min(tree3[node*2],tree3[node*2+1]);
}

inline int query2(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return -inf;
	push2(node,start,end);
	if(start>=l && end<=r){return tree2[node];}
	return max(query2(node*2,start,mid,l,r),query2(node*2+1,mid+1,end,l,r));
}
 
inline int query3(int node,int start,int end,int l,int r){
	if(start>end || start>r || end<l)return inf;
	push3(node,start,end);
	if(start>=l && end<=r){return tree3[node];}
	return min(query3(node*2,start,mid,l,r),query3(node*2+1,mid+1,end,l,r));
}
 
main(void){
	//~ freopen("simple.txt","r",stdin);
	//~ freopen("simpleo.txt","w",stdout);
	//~ printf("**\n");
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
		b[i]=inf-1-a[i];
		a[i]=inf+a[i];
	}
	scanf("%lld",&t);
	build(1,1,n);
	build3(1,1,n);
	build2(1,1,n);
	build1(1,1,n);
	int ok=0;
	while(t--){
		int type,x,y;
		scanf("%lld %lld %lld",&type,&x,&y);
		//~ if(type==0){printf("()\n");return 0;}
		if(type==1){
			int say=query2(1,1,n,x,y);
			int say1=query(1,1,n,x,y);
			say=inf-1-say;
			say1-=inf;
			if(say1%2==0 || say1<0)say1=-1;
			if(say%2==1 || say<0)say=-1;
			printf("%lld %lld\n",say,say1);
		}
		else{
			scanf("%lld",&val);
			update(1,1,n,x,y);
			update2(1,1,n,x,y);
			update1(1,1,n,x,y);
			update3(1,1,n,x,y);
		}
		//~ ok++;
		//~ if(ok==25)
		//~ return 0;
	}
	return 0;
}

Compilation message

subway.cpp:204:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(void){
          ^
subway.cpp: In function 'int main()':
subway.cpp:219:6: warning: unused variable 'ok' [-Wunused-variable]
  int ok=0;
      ^~
subway.cpp:208:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
subway.cpp:210:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
   ~~~~~^~~~~~~~~~~~~~
subway.cpp:214:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&t);
  ~~~~~^~~~~~~~~~~
subway.cpp:222:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld",&type,&x,&y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subway.cpp:234:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld",&val);
    ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1152 KB Output is correct
2 Correct 13 ms 1152 KB Output is correct
3 Correct 16 ms 1664 KB Output is correct
4 Correct 14 ms 1792 KB Output is correct
5 Correct 15 ms 1664 KB Output is correct
6 Correct 14 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 14276 KB Output is correct
2 Correct 385 ms 26860 KB Output is correct
3 Correct 384 ms 27000 KB Output is correct
4 Correct 374 ms 26744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1152 KB Output is correct
2 Correct 13 ms 1152 KB Output is correct
3 Correct 16 ms 1664 KB Output is correct
4 Correct 14 ms 1792 KB Output is correct
5 Correct 15 ms 1664 KB Output is correct
6 Correct 14 ms 1664 KB Output is correct
7 Correct 177 ms 14276 KB Output is correct
8 Correct 385 ms 26860 KB Output is correct
9 Correct 384 ms 27000 KB Output is correct
10 Correct 374 ms 26744 KB Output is correct
11 Correct 318 ms 22964 KB Output is correct
12 Correct 812 ms 42360 KB Output is correct
13 Correct 693 ms 46200 KB Output is correct
14 Correct 806 ms 45432 KB Output is correct
15 Correct 608 ms 46712 KB Output is correct
16 Correct 135 ms 26360 KB Output is correct