답안 #87151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
87151 2018-11-29T18:16:35 Z rzbt Simple game (IZhO17_game) C++14
100 / 100
127 ms 22768 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 100005
#define MAXF 1000006
typedef long long ll;

using namespace std;
int bit[MAXF];
int niz[MAXN];
void dodaj(int p,int x){
    for(;p<MAXF;p+=(-p)&p)
        bit[p]+=x;
}

int dobij(int p){
    int zbir=0;
    for(;p>0;p-=(-p)&p)
        zbir+=bit[p];
    return zbir;
}

void range(int a,int b,int x){
    dodaj(a,x);
    dodaj(b+1,-x);
}



int n,m;


int main()
{
    scanf("%d %d", &n, &m);
    scanf("%d",niz+1);
    for(int i=2;i<=n;i++){
        scanf("%d",niz+i);
        range(min(niz[i],niz[i-1]),max(niz[i],niz[i-1]),1);
    }
    for(int i=1;i<=m;i++){
        int q;
        scanf("%d", &q);
        if(q==1){
            int t1,t2;
            scanf("%d %d", &t1, &t2);
            if(t1!=1)range(min(niz[t1],niz[t1-1]),max(niz[t1],niz[t1-1]),-1);
            if(t1!=n)range(min(niz[t1],niz[t1+1]),max(niz[t1],niz[t1+1]),-1);
            niz[t1]=t2;
            if(t1!=1)range(min(niz[t1],niz[t1-1]),max(niz[t1],niz[t1-1]),1);
            if(t1!=n)range(min(niz[t1],niz[t1+1]),max(niz[t1],niz[t1+1]),1);
        }else{
            int t;
            scanf("%d", &t);
            printf("%d\n",dobij(t));
        }

    }

    return 0;
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",niz+1);
     ~~~~~^~~~~~~~~~~~
game.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",niz+i);
         ~~~~~^~~~~~~~~~~~
game.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &q);
         ~~~~~^~~~~~~~~~
game.cpp:49:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &t1, &t2);
             ~~~~~^~~~~~~~~~~~~~~~~~~
game.cpp:57:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &t);
             ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 4220 KB Output is correct
3 Correct 6 ms 4224 KB Output is correct
4 Correct 6 ms 4320 KB Output is correct
5 Correct 7 ms 4376 KB Output is correct
6 Correct 6 ms 4584 KB Output is correct
7 Correct 5 ms 4584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 4220 KB Output is correct
3 Correct 6 ms 4224 KB Output is correct
4 Correct 6 ms 4320 KB Output is correct
5 Correct 7 ms 4376 KB Output is correct
6 Correct 6 ms 4584 KB Output is correct
7 Correct 5 ms 4584 KB Output is correct
8 Correct 96 ms 4584 KB Output is correct
9 Correct 105 ms 8100 KB Output is correct
10 Correct 103 ms 9924 KB Output is correct
11 Correct 58 ms 9924 KB Output is correct
12 Correct 60 ms 9924 KB Output is correct
13 Correct 73 ms 9924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 4220 KB Output is correct
3 Correct 6 ms 4224 KB Output is correct
4 Correct 6 ms 4320 KB Output is correct
5 Correct 7 ms 4376 KB Output is correct
6 Correct 6 ms 4584 KB Output is correct
7 Correct 5 ms 4584 KB Output is correct
8 Correct 96 ms 4584 KB Output is correct
9 Correct 105 ms 8100 KB Output is correct
10 Correct 103 ms 9924 KB Output is correct
11 Correct 58 ms 9924 KB Output is correct
12 Correct 60 ms 9924 KB Output is correct
13 Correct 73 ms 9924 KB Output is correct
14 Correct 107 ms 14912 KB Output is correct
15 Correct 99 ms 17016 KB Output is correct
16 Correct 116 ms 18868 KB Output is correct
17 Correct 103 ms 20808 KB Output is correct
18 Correct 127 ms 22768 KB Output is correct