# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
37461 |
2017-12-25T15:05:43 Z |
Kerim |
Simple game (IZhO17_game) |
C++14 |
|
0 ms |
21548 KB |
#include "bits/stdc++.h"
#define MAXN 1000009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int s[MAXN<<2],arr[MAXN];
void inc(int l,int r,int val,int nd,int x,int y){
if(l>r or l>y or x>r)
return;
if(l<=x and y<=r){
s[nd]+=val;
return;
}
int mid=(x+y)>>1;
inc(l,r,val,nd<<1,x,mid);
inc(l,r,val,nd<<1|1,mid+1,y);
}
int tap(int p,int nd,int x,int y){
if(x==y)
return s[nd];
int mid=(x+y)>>1;
if(p<=mid)
return s[nd]+tap(p,nd<<1,x,mid);
return s[nd]+tap(p,nd<<1|1,mid+1,y);
}
int main(){
//~ freopen("file.in", "r", stdin);
int n,q;
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++)
scanf("%d",arr+i);
for(int i=1;i<n;i++)
inc(min(arr[i],arr[i+1]),max(arr[i],arr[i+1]),+1,1,1,n);
while(q--){
int t;
scanf("%d",&t);
if(t==1){
int p,v;
scanf("%d%d",&p,&v);
if(p>1)
inc(min(arr[p],arr[p-1]),max(arr[p],arr[p-1]),-1,1,1,n);
if(p<n)
inc(min(arr[p],arr[p+1]),max(arr[p],arr[p+1]),-1,1,1,n);
arr[p]=v;
if(p>1)
inc(min(arr[p],arr[p-1]),max(arr[p],arr[p-1]),+1,1,1,n);
if(p<n)
inc(min(arr[p],arr[p+1]),max(arr[p],arr[p+1]),+1,1,1,n);
}
else{
int p;
scanf("%d",&p);
printf("%d\n",tap(p,1,1,n));
}
}
return 0;
}
Compilation message
game.cpp: In function 'int main()':
game.cpp:43:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&q);
^
game.cpp:45:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",arr+i);
^
game.cpp:50:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&t);
^
game.cpp:53:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&p,&v);
^
game.cpp:66:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&p);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21548 KB |
Output is correct |
2 |
Incorrect |
0 ms |
21548 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21548 KB |
Output is correct |
2 |
Incorrect |
0 ms |
21548 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21548 KB |
Output is correct |
2 |
Incorrect |
0 ms |
21548 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |