# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
593311 | LucaGreg | Simple game (IZhO17_game) | C++17 | 1089 ms | 6800 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int sp[1000010];
int h[100010];
int main()
{
int n, m; scanf("%d %d", &n, &m);
scanf("%d", &h[1]);
for(int i=2;i<=n;i++){
scanf("%d", &h[i]);
sp[min(h[i-1], h[i])]++;
sp[max(h[i-1], h[i])+1]--;
}
for(int i=1;i<=1000001;i++){
sp[i] += sp[i-1];
}
for(int i=0;i<m;i++){
int t; scanf("%d", &t);
if(t==2){
int hq; scanf("%d", &hq);
printf("%d\n", sp[hq]);
}else if(t==1){
int pos, val; scanf("%d %d", &pos, &val);
if(pos==1){
//elimina a chain com o vertice seguinte
for(int j=min(h[pos], h[pos+1]);j<=max(h[pos], h[pos+1]);j++){
sp[j]--;
}
//cria a chain(com a nova altura) com o vertice seguinte
for(int j=min(val, h[pos+1]);j<=max(val, h[pos+1]);j++){
sp[j]++;
}
}else if(pos==n){
//elimina a chain com o vertice anterior
for(int j=min(h[pos], h[pos-1]);j<=max(h[pos], h[pos-1]);j++){
sp[j]--;
}
//cria a chain(com a nova altura) com o vertice anterior
for(int j=min(val, h[pos-1]);j<=max(val, h[pos-1]);j++){
sp[j]++;
}
}else{
//elimina a chain com o vertice seguinte
for(int j=min(h[pos], h[pos+1]);j<=max(h[pos], h[pos+1]);j++){
sp[j]--;
}
//elimina a chain com o vertice anterior
for(int j=min(h[pos], h[pos-1]);j<=max(h[pos], h[pos-1]);j++){
sp[j]--;
}
//cria a chain(com a nova altura) com o vertice seguinte
for(int j=min(val, h[pos+1]);j<=max(val, h[pos+1]);j++){
sp[j]++;
}
//cria a chain(com a nova altura) com o vertice anterior
for(int j=min(val, h[pos-1]);j<=max(val, h[pos-1]);j++){
sp[j]++;
}
}
h[pos] = val;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |