Submission #5021272
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned ui; typedef unsigned long long ul; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; typedef pair<bool, bool> pbb; typedef vector<int> vi; #define pb push_back #define fi first #define se second #define mid ((l + r) >> 1) #define ls (i << 1) #define rs (i << 1 | 1) #define enum(i, j, k) for(int i = j; i <= (k); i ++) #define open(i, j, k) for(int i = j; i < (k); i ++) #define dec(i, j, k) for(int i = j; i >= (k); i --) #define ae(x) for(node *p = h[x]; p; p = p->nxt) #define fill(x, k) memset(x, k, sizeof x) #define copy(x, y) memcpy(x, y, sizeof x) #define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout); template <class T> bool chkmin(T &x, T y) { return y < x ? (x = y , true) : false; } template <class T> bool chkmax(T &x, T y) { return y > x ? (x = y , true) : false; } void __init() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(16); srand(time(0) ^ ui(ul(new char))); } /* default code ends here */ const int maxn = 2e5 + 10; int n, m, ans; int a[maxn]; map<int, int> mp; void add(int x) { auto it = mp.find(x); if(it != mp.end()) { auto it2 = -- mp.lower_bound(x); if((*it).fi - (*it2).fi <= (*it).se) ans ++; (*it).se ++; } else { auto it2 = mp.upper_bound(x), it3 = it2 --; int d = (*it3).fi - (*it2).fi - (*it3).se; if(d < 0) ans += d; d = (*it3).fi - x - (*it3).se; if(d < 0) ans -= d; d = x - (*it2).fi - 1; if(d < 0) ans -= d; mp[x] = 1; } } void del(int x) { auto it = mp.find(x); if((*it).se != 1) { auto it2 = -- mp.lower_bound(x); if((*it).fi - (*it2).fi < (*it).se) ans --; (*it).se --; } else { mp.erase(it); auto it2 = mp.upper_bound(x), it3 = it2 --; int d = (*it3).fi - x - (*it3).se; if(d < 0) ans += d; d = x - (*it2).fi - 1; if(d < 0) ans += d; d = (*it3).fi - (*it2).fi - (*it3).se; if(d < 0) ans -= d; } } int main() { __init(); cin >> n >> m; mp[0] = 1; mp[n + 1] = 1; enum(i, 1, n) cin >> a[i]; enum(i, 1, n) add(a[i]); int x, y; while(m --) { cin >> x >> y; del(a[x]); a[x] = y; add(a[x]); cout << ans << '\n'; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Snuke and Spells |
User | Jiangkp |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2368 Byte |
Status | WA |
Exec Time | 369 ms |
Memory | 11520 KB |
Judge Result
Set Name | Sample | subtask | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 500 | 0 / 500 | ||||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
subtask | sample1.txt, sample2.txt, sample3.txt, subtask_a1.txt, subtask_a2.txt, subtask_a3.txt, subtask_a4.txt, subtask_a5.txt, subtask_a6.txt, subtask_b1.txt, subtask_b2.txt, subtask_c1.txt, subtask_c2.txt, subtask_d1.txt, subtask_d2.txt, subtask_d3.txt, subtask_d4.txt, subtask_e1.txt, subtask_e2.txt, subtask_e3.txt, subtask_e4.txt, subtask_f1.txt, subtask_f2.txt |
All | sample1.txt, sample2.txt, sample3.txt, a1.txt, a2.txt, a3.txt, a4.txt, a5.txt, a6.txt, b1.txt, b2.txt, c1.txt, c2.txt, d1.txt, d2.txt, d3.txt, d4.txt, e1.txt, e2.txt, e3.txt, e4.txt, f1.txt, f2.txt, sample1.txt, sample2.txt, sample3.txt, subtask_a1.txt, subtask_a2.txt, subtask_a3.txt, subtask_a4.txt, subtask_a5.txt, subtask_a6.txt, subtask_b1.txt, subtask_b2.txt, subtask_c1.txt, subtask_c2.txt, subtask_d1.txt, subtask_d2.txt, subtask_d3.txt, subtask_d4.txt, subtask_e1.txt, subtask_e2.txt, subtask_e3.txt, subtask_e4.txt, subtask_f1.txt, subtask_f2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
a1.txt | WA | 340 ms | 8192 KB |
a2.txt | WA | 339 ms | 8192 KB |
a3.txt | WA | 337 ms | 8064 KB |
a4.txt | WA | 338 ms | 8064 KB |
a5.txt | WA | 329 ms | 7808 KB |
a6.txt | WA | 340 ms | 8192 KB |
b1.txt | WA | 367 ms | 11520 KB |
b2.txt | WA | 369 ms | 11520 KB |
c1.txt | WA | 359 ms | 11520 KB |
c2.txt | WA | 356 ms | 11520 KB |
d1.txt | WA | 363 ms | 11520 KB |
d2.txt | WA | 365 ms | 11520 KB |
d3.txt | WA | 358 ms | 11520 KB |
d4.txt | WA | 356 ms | 11520 KB |
e1.txt | WA | 357 ms | 11520 KB |
e2.txt | WA | 354 ms | 11392 KB |
e3.txt | WA | 358 ms | 11264 KB |
e4.txt | WA | 361 ms | 10880 KB |
f1.txt | AC | 75 ms | 2304 KB |
f2.txt | AC | 78 ms | 2304 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |
subtask_a1.txt | WA | 1 ms | 256 KB |
subtask_a2.txt | WA | 1 ms | 256 KB |
subtask_a3.txt | WA | 1 ms | 256 KB |
subtask_a4.txt | WA | 1 ms | 256 KB |
subtask_a5.txt | WA | 1 ms | 256 KB |
subtask_a6.txt | WA | 1 ms | 256 KB |
subtask_b1.txt | WA | 1 ms | 256 KB |
subtask_b2.txt | WA | 1 ms | 256 KB |
subtask_c1.txt | WA | 1 ms | 256 KB |
subtask_c2.txt | WA | 1 ms | 256 KB |
subtask_d1.txt | WA | 1 ms | 256 KB |
subtask_d2.txt | WA | 1 ms | 256 KB |
subtask_d3.txt | WA | 1 ms | 256 KB |
subtask_d4.txt | WA | 1 ms | 256 KB |
subtask_e1.txt | WA | 1 ms | 256 KB |
subtask_e2.txt | WA | 1 ms | 256 KB |
subtask_e3.txt | WA | 1 ms | 256 KB |
subtask_e4.txt | WA | 1 ms | 256 KB |
subtask_f1.txt | AC | 1 ms | 256 KB |
subtask_f2.txt | AC | 1 ms | 256 KB |