답안 #567651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
567651 2022-05-24T00:00:03 Z robs Simple game (IZhO17_game) C++17
0 / 100
4 ms 3728 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5;
int BIT[maxn], v[maxn];

void update(int id, int val)
{
  while(id < maxn)
  {
    BIT[id] += val;
    id += id&-id;
  }
}

int query(int id)
{
  int aux = 0;
  while(id > 0)
  {
    aux += BIT[id];
    id -= id&-id;
  }

  return aux;
}

int main(){
  int n, m;
  scanf("%d %d",&n,&m);

  for(int i = 1; i <= n; i++)
    scanf("%d",&v[i]);
  
  for(int i = 1; i < n; i++)
  {
    update(min(v[i], v[i+1]), 1);
    update(max(v[i], v[i+1])+1, -1);
  }

  for(int i = 1; i <= m; i++)
  {
    int tp;
    scanf("%d",&tp);

    if(tp == 1)
    {
      int id, val;
      scanf("%d %d",&id,&val);

      update(min(v[id], v[id+1]), -1);
      update(max(v[id], v[id+1])+1, 1);

      v[id] = val;

      update(min(v[id], v[id+1]), 1);
      update(max(v[id], v[id+1])+1, -1);
    }
    if(tp == 2)
    {
      int val;
      scanf("%d",&val);

      int resp = query(val);
      printf("%d\n",resp);
    }
  }
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf("%d %d",&n,&m);
      |   ~~~~~^~~~~~~~~~~~~~~
game.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d",&v[i]);
      |     ~~~~~^~~~~~~~~~~~
game.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d",&tp);
      |     ~~~~~^~~~~~~~~~
game.cpp:48:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |       scanf("%d %d",&id,&val);
      |       ~~~~~^~~~~~~~~~~~~~~~~~
game.cpp:61:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |       scanf("%d",&val);
      |       ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 4 ms 3728 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 4 ms 3728 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 4 ms 3728 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -