# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
37465 |
2017-12-25T15:34:31 Z |
Kerim |
Simple game (IZhO17_game) |
C++14 |
|
326 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,1000000);
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,1000000);
if(p<n)
inc(min(arr[p],arr[p+1]),max(arr[p],arr[p+1]),-1,1,1,1000000);
arr[p]=v;
if(p>1)
inc(min(arr[p],arr[p-1]),max(arr[p],arr[p-1]),+1,1,1,1000000);
if(p<n)
inc(min(arr[p],arr[p+1]),max(arr[p],arr[p+1]),+1,1,1,1000000);
}
else{
int p;
scanf("%d",&p);
printf("%d\n",tap(p,1,1,1000000));
}
}
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 |
Correct |
3 ms |
21548 KB |
Output is correct |
3 |
Correct |
6 ms |
21548 KB |
Output is correct |
4 |
Correct |
3 ms |
21548 KB |
Output is correct |
5 |
Correct |
6 ms |
21548 KB |
Output is correct |
6 |
Correct |
0 ms |
21548 KB |
Output is correct |
7 |
Correct |
0 ms |
21548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21548 KB |
Output is correct |
2 |
Correct |
3 ms |
21548 KB |
Output is correct |
3 |
Correct |
6 ms |
21548 KB |
Output is correct |
4 |
Correct |
3 ms |
21548 KB |
Output is correct |
5 |
Correct |
6 ms |
21548 KB |
Output is correct |
6 |
Correct |
0 ms |
21548 KB |
Output is correct |
7 |
Correct |
0 ms |
21548 KB |
Output is correct |
8 |
Correct |
76 ms |
21548 KB |
Output is correct |
9 |
Correct |
173 ms |
21548 KB |
Output is correct |
10 |
Correct |
149 ms |
21548 KB |
Output is correct |
11 |
Correct |
66 ms |
21548 KB |
Output is correct |
12 |
Correct |
103 ms |
21548 KB |
Output is correct |
13 |
Correct |
89 ms |
21548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21548 KB |
Output is correct |
2 |
Correct |
3 ms |
21548 KB |
Output is correct |
3 |
Correct |
6 ms |
21548 KB |
Output is correct |
4 |
Correct |
3 ms |
21548 KB |
Output is correct |
5 |
Correct |
6 ms |
21548 KB |
Output is correct |
6 |
Correct |
0 ms |
21548 KB |
Output is correct |
7 |
Correct |
0 ms |
21548 KB |
Output is correct |
8 |
Correct |
76 ms |
21548 KB |
Output is correct |
9 |
Correct |
173 ms |
21548 KB |
Output is correct |
10 |
Correct |
149 ms |
21548 KB |
Output is correct |
11 |
Correct |
66 ms |
21548 KB |
Output is correct |
12 |
Correct |
103 ms |
21548 KB |
Output is correct |
13 |
Correct |
89 ms |
21548 KB |
Output is correct |
14 |
Correct |
326 ms |
21548 KB |
Output is correct |
15 |
Correct |
303 ms |
21548 KB |
Output is correct |
16 |
Correct |
309 ms |
21548 KB |
Output is correct |
17 |
Correct |
303 ms |
21548 KB |
Output is correct |
18 |
Correct |
309 ms |
21548 KB |
Output is correct |