Submission #229531

# Submission time Handle Problem Language Result Execution time Memory
229531 2020-05-04T22:57:46 Z blacktulip Simple (info1cup19_simple) C++17
30 / 100
398 ms 23800 KB
#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 = 10000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 200005;
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){
	push1(node,start,end);
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){push1(node,start,end);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){
	push3(node,start,end);
	if(start>end || start>r || end<l)return ;
	if(start>=l && end<=r){push3(node,start,end);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);
	//~ printf("**\n");
	scanf("%lld",&n);
	FOR{
		scanf("%lld",&a[i]);
		b[i]=inf-1-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;
			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:203:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(void){
          ^
subway.cpp: In function 'int main()':
subway.cpp:216:6: warning: unused variable 'ok' [-Wunused-variable]
  int ok=0;
      ^~
subway.cpp:206:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
subway.cpp:208:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
   ~~~~~^~~~~~~~~~~~~~
subway.cpp:211:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&t);
  ~~~~~^~~~~~~~~~~
subway.cpp:219: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:230: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 Incorrect 13 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 184 ms 12028 KB Output is correct
2 Correct 394 ms 23800 KB Output is correct
3 Correct 382 ms 23544 KB Output is correct
4 Correct 398 ms 23536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -