이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
int n, q;
int a[N];
int t[N * 4];
void ubd(int tl, int tr, int l, int r, int y, int pos)
{
if (tl == l && tr == r)
{
t[pos] += y;
return;
}
int m = (tl + tr) / 2;
if (r <= m)
ubd(tl, m, l, r, y, pos * 2);
else if (l > m)
ubd(m + 1, tr, l, r, y, pos * 2 + 1);
else
{
ubd(tl, m, l, m, y, pos * 2);
ubd(m + 1, tr, m + 1, r, y, pos * 2 + 1);
}
}
int qry(int tl, int tr, int x, int pos)
{
if (tl == tr)
return t[pos];
int m = (tl + tr) / 2;
if (x <= m)
return t[pos] + qry(tl, m, x, pos * 2);
else
return t[pos] + qry(m + 1, tr, x, pos * 2 + 1);
}
int main()
{
//freopen("input2.txt", "r", stdin);
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (int i = 1; i < n; ++i)
{
ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1, 1);
}
while (q--)
{
int ty;
scanf("%d", &ty);
if (ty == 1)
{
int i, x;
scanf("%d%d", &i, &x);
if (i == 1)
ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), -1, 1);
else if (i == n)
ubd(1, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), -1, 1);
else
{
ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), -1, 1);
ubd(1, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), -1, 1);
}
a[i] = x;
if (i == 1)
ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1, 1);
else if (i == n)
ubd(1, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), 1, 1);
else
{
ubd(1, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1, 1);
ubd(1, N - 1, min(a[i], a[i - 1]), max(a[i], a[i - 1]), 1, 1);
}
}
else
{
int x;
scanf("%d", &x);
cout << qry(1, N - 1, x, 1) << endl;
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In function 'int main()':
game.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~
game.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
game.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &ty);
~~~~~^~~~~~~~~~~
game.cpp:56:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &i, &x);
~~~~~^~~~~~~~~~~~~~~~
game.cpp:80:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &x);
~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |