이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 4e6 + 42, H = 1e6 + 42;
int t[N];
void update (int v, int tl, int tr, int l, int r, int add) {
if (l > r)
return;
if (l == tl && tr == r)
t[v] += add;
else {
int tm = (tl + tr) / 2;
update (v*2, tl, tm, l, min(r,tm), add);
update (v*2+1, tm+1, tr, max(l,tm+1), r, add);
}
}
int get (int v, int tl, int tr, int pos) {
if (tl == tr)
return t[v];
int tm = (tl + tr) / 2;
if (pos <= tm)
return t[v] + get (v*2, tl, tm, pos);
else
return t[v] + get (v*2+1, tm+1, tr, pos);
}
int n, m;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
vector<int> h(n);
for(int i = 0; i < n; i++) {
cin >> h[i];
if(i) {
update(1, 0, H - 1, min(h[i], h[i - 1]), max(h[i], h[i - 1]), 1);
}
}
map<int, int> amm;
for(int i = 1; i < n - 1; i++) amm[h[i]]++;
while(m--) {
int t; cin >> t;
if(t == 2) {
int ch; cin >> ch;
cout << get(1, 0, H - 1, ch) - amm[ch] << '\n';
} else {
int ci, ch; cin >> ci >> ch;
ci--;
if(ci > 0 && ci < n - 1) amm[h[ci]]--;
if(ci + 1 < n) {
update(1, 0, H - 1, min(h[ci], h[ci + 1]), max(h[ci], h[ci + 1]), -1);
}
if(ci - 1 >= 0) {
update(1, 0, H - 1, min(h[ci], h[ci - 1]), max(h[ci], h[ci - 1]), -1);
}
h[ci] = ch;
if(ci + 1 < n) {
update(1, 0, H - 1, min(h[ci], h[ci + 1]), max(h[ci], h[ci + 1]), 1);
}
if(ci - 1 >= 0) {
update(1, 0, H - 1, min(h[ci], h[ci - 1]), max(h[ci], h[ci - 1]), 1);
}
if(ci > 0 && ci < n - 1) amm[h[ci]]++;
}
}
return 0;
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
game.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |