Submission #575940

# Submission time Handle Problem Language Result Execution time Memory
575940 2022-06-11T22:28:19 Z robs Simple game (IZhO17_game) C++17
0 / 100
4 ms 3796 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++)
  {
    int ini = v[i], fim = v[i+1];

    if(ini > fim) swap(ini, fim);
    update(ini, 1);
    update(fim+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);

      int ant = v[id-1], cur = v[id], nxt = v[id+1];
      
      if(id != 1)
      {
        update(min(ant, cur), -1);
        update(max(ant, cur)+1, 1);
      }

      if(id != n)
      {
        update(min(cur, nxt), -1);
        update(max(cur, nxt)+1, 1);
      }

      v[id] = cur = val;

      if(id != 1)
      {
        update(min(ant, cur), 1);
        update(max(ant, cur)+1, -1);
      }

      if(id != n)
      {
        update(min(cur, nxt), 1);
        update(max(cur, nxt)+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:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%d",&tp);
      |     ~~~~~^~~~~~~~~~
game.cpp:51:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |       scanf("%d %d",&id,&val);
      |       ~~~~~^~~~~~~~~~~~~~~~~~
game.cpp:84:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |       scanf("%d",&val);
      |       ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 4 ms 3796 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 4 ms 3796 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Runtime error 4 ms 3796 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -