Submission #491481

#TimeUsernameProblemLanguageResultExecution timeMemory
491481patrikpavic2Employment (JOI16_employment)C++17
100 / 100
237 ms12308 KiB
#include <cstdio> #include <vector> #include <algorithm> #define PB push_back using namespace std; int n, q; const int N = 4e5 + 500; int loga[N], A[N]; void add(int x, int y){ for(x += 10; x < N ; x += x & -x) loga[x] += y; } int query(int x){ int ret = 0; for(x += 10; x ; x -= x & -x) ret += loga[x]; return ret; } vector < int > saz; int ty[N], pos[N], B[N]; void dodaj(int i, int kof){ add(min(A[i], A[i + 1]) + 1, kof); add(max(A[i], A[i + 1]) + 1, -kof); } int main(){ scanf("%d%d", &n, &q); saz.PB(0); for(int i = 1;i <= n;i++){ scanf("%d", A + i); saz.PB(A[i]); } for(int i = 0;i < q;i++){ scanf("%d", ty + i); if(ty[i] - 1) scanf("%d", pos + i); scanf("%d", B + i); saz.PB(B[i]); } sort(saz.begin(), saz.end()); saz.erase(unique(saz.begin(), saz.end()), saz.end()); for(int i = 1;i <= n;i++) A[i] = lower_bound(saz.begin(), saz.end(), A[i]) - saz.begin(); for(int i = 0;i <= n;i++){ dodaj(i, 1); } for(int i = 0;i < q;i++){ B[i] = lower_bound(saz.begin(), saz.end(), B[i]) - saz.begin(); if(ty[i] - 1){ dodaj(pos[i] - 1, -1); dodaj(pos[i], -1); A[pos[i]] = B[i]; dodaj(pos[i] - 1, 1); dodaj(pos[i], 1); } else printf("%d\n", query(B[i]) / 2); } return 0; }

Compilation message (stderr)

employment.cpp: In function 'int main()':
employment.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d", A + i);
      |   ~~~~~^~~~~~~~~~~~~
employment.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d", ty + i);
      |   ~~~~~^~~~~~~~~~~~~~
employment.cpp:44:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |    scanf("%d", pos + i);
      |    ~~~~~^~~~~~~~~~~~~~~
employment.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d", B + i);
      |   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...