#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
struct Fenwick {
int n;
vector <int> f;
Fenwick (int _n): n(_n), f(_n + 5) {};
int qry(int x) {
int ans = 0;
for (; x; x -= x & -x)
ans += f[x];
return ans;
}
void add(int x, int val) {
for (; x <= n; x += x & -x)
f[x] += val;
}
};
const int N = 1e6 + 5;
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int n, q;
cin >> n >> q;
vector <int> h(n + 5);
vector <vector <int>> queries(q + 5);
for (int i = 1; i <= n; ++i) cin >> h[i];
bool sub2 = 1;
for (int i = 1; i <= q; ++i) {
int cmd; cin >> cmd;
if (cmd == 1) {
int x, y; cin >> x >> y;
queries[i] = {cmd, x, y};
sub2 = 0;
}
else {
int x; cin >> x;
queries[i] = {cmd, x};
}
}
// sub1
if (n <= 1000 && q <= 1000) {
for (int i = 1; i <= q; ++i) {
if (queries[i][0] == 1)
h[queries[i][1]] = queries[i][2];
else {
int ans = 0;
for (int j = 1; j <= n; ++j)
if (h[j] <= queries[i][1])
++ans;
cout << ans << "\n";
}
}
}
else if (sub2) {
// Fenwick
vector <int> cnt(N);
for (int i = 1; i <= n; ++i) cnt[h[i]]++;
for (int i = 1; i < N; ++i) cnt[i] += cnt[i - 1];
for (int i = 1; i <= q; ++i) {
cout << cnt[queries[i][1]] << "\n";
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |