QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#608750 | #6117. Determine The Fluctuation Bonus | qtoq | WA | 183ms | 14208kb | C++17 | 3.8kb | 2024-10-04 02:26:28 | 2024-10-04 02:26:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef ONPC
#define deb(...) cerr << '[' << __FILE__ << ':' << __LINE__ << "] (" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define deb(...)
#endif
// c++ short types
#define vt vector
//typedef long long ll;
typedef long double ld;
void whattime() { cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; }
// const int mod = 1e9 + 7;
const int mod = 998244353;
const int inf = 1e9;
const int64_t infll = 1e13;
bool debug = false;
const ld eps = 1e-9;
const ld pi = acos(-1);
mt19937_64 rng((int) chrono::steady_clock::now().time_since_epoch().count());
class Segtree {
public:
vt<int> cnt;
vt<int> delta;
int n;
Segtree(int _n) : n(_n) {
cnt = vt<int>(2*n, 0);
delta = vt<int>(2*n, 0);
}
void update_delta(int l, int r, int dx) {
for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
if(l & 1) {
delta[l] += dx;
l++;
}
if(r & 1) {
--r;
delta[r] += dx;
}
}
}
int get_delta(int pos) {
int res = 0;
pos += n;
while(pos) {
res += delta[pos];
pos >>= 1;
}
return res;
}
void update_cnt(int pos, int dx) {
pos += n;
while(pos) {
cnt[pos] += dx;
pos >>= 1;
}
}
int get_cnt(int l, int r) {
int res = 0;
for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
if(l & 1) {
res += cnt[l];
++l;
}
if(r & 1) {
--r;
res += cnt[r];
}
}
return res;
}
};
void solve() {
int n, q;
cin >> n >> q;
vt<int> a(q), p(q);
vt<int64_t> cost(n, 0);
map<int64_t, int> ids;
ids[0];
for(int i = 0; i < q; ++i) {
cin >> a[i] >> p[i];
--a[i];
cost[a[i]] += p[i];
ids[cost[a[i]]];
}
ids[0];
int id = 0;
for(auto &[v, i]: ids) {
i = id++;
}
vt<int64_t> coins(n, 0);
Segtree st(id + 1);
st.update_cnt(ids[0], n);
cost = vt<int64_t>(n, 0);
for(int i = 0; i < q; ++i) {
int before = ids[cost[a[i]]];
cost[a[i]] += p[i];
int after = ids[cost[a[i]]];
deb(before, after);
if(before < after) {
st.update_cnt(before, -1);
coins[a[i]] += st.get_delta(before);
coins[a[i]] += st.get_cnt(before + 1, after + 1);
st.update_delta(before, after, + 1);
coins[a[i]] -= st.get_delta(after);
st.update_cnt(after, + 1);
} else if(before > after) {
st.update_cnt(before, -1);
coins[a[i]] += st.get_delta(before);
coins[a[i]] += st.get_cnt(after+1, before+1);
st.update_delta(after + 1, before, + 1);
coins[a[i]] -= st.get_delta(after);
st.update_cnt(after, + 1);
}
// for(int j = 0; j < n; ++j) {
// int64_t val = coins[j] + st.get_delta(ids[cost[j]]);
// deb(j, val, cost[j]);
// }
}
for(int i = 0; i < n; ++i) {
cout << coins[i] + st.get_delta(ids[cost[i]]) << '\n';
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
// freopen("/home/raf/CLionProjects/cp/inp.txt", "r", stdin);
int tt = 1;;
if(debug) {
tt = 1e3;
} else {
}
for(int t = 0; t < tt; ++t) {
solve();
}
#ifdef ONPC
whattime();
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
3 7 2 -1 1 4 2 5 3 6 1 -7 3 -6 2 9
output:
2 6 5
result:
ok 3 number(s): "2 6 5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
9 5 2 10 2 -20 2 20 2 -20 2 20
output:
5 32 5 5 5 5 5 5 5
result:
ok 9 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
5 10 1 0 3 0 2 0 5 0 4 0 1 0 3 0 2 0 5 0 4 0
output:
0 0 0 0 0
result:
ok 5 number(s): "0 0 0 0 0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1 1 1 0
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
1 1 1 -1000000000
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
1 1 1 1000000000
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 119ms
memory: 11920kb
input:
34 99924 5 384094577 32 -796292690 21 -811649302 16 962640530 11 -949299967 26 946724925 32 -871556791 13 -597225272 5 -462265209 17 -360565332 30 973334595 26 65508285 25 -313976558 11 -305308663 4 44272276 3 505903660 19 -828537724 7 -809263187 5 -127755414 19 168244448 13 451711380 17 706137232 2...
output:
1710 2465 2377 1036 2028 1650 2222 2291 2113 579 1536 1820 2479 1610 2210 1395 2213 2289 804 1996 2692 1363 1395 767 1668 1740 1103 1954 1101 2137 1869 1735 2466 2356
result:
ok 34 numbers
Test #8:
score: 0
Accepted
time: 122ms
memory: 11804kb
input:
443 99904 355 776573502 441 -293834208 375 -837011997 40 2774488 397 -249123167 69 -668289981 43 126338528 157 72371393 305 -608040225 253 -492951696 117 -13750067 77 -926024146 115 -887142637 146 585581525 118 -262829358 48 683226063 235 -844096239 69 513944511 223 -498788495 241 -911077572 113 -93...
output:
7435 7270 6432 7641 2790 7721 3771 6005 7048 6948 7038 6544 7023 7418 7049 5335 5809 5634 5960 4388 5976 7737 6746 3312 7530 1984 6800 7404 6116 7491 4906 5022 7280 6565 7198 6032 7810 2660 1697 7036 4367 8059 4639 8228 5447 6877 6983 6887 2793 7200 7466 6033 5821 7692 7465 7800 7458 5839 6406 7130 ...
result:
ok 443 numbers
Test #9:
score: 0
Accepted
time: 122ms
memory: 11856kb
input:
240 99983 104 -95278518 231 572854945 93 -368197265 174 -738422454 193 521431685 90 655012878 65 301059792 147 -403962108 21 -858177820 87 223139155 181 -959038878 68 -14423910 30 -699054356 120 435440768 82 983702786 63 211402654 217 92961114 162 -358114816 23 779543403 160 -455406864 201 -48723282...
output:
4457 4667 4950 6031 3883 4270 6068 6035 4719 2709 1574 4796 5219 2339 4844 5880 2683 5995 2596 5281 5413 5607 4429 5419 5911 5350 5792 5301 4988 3019 5353 756 5064 4800 3912 4133 4306 2924 5941 5976 4870 4644 4357 4481 3119 4770 5603 5480 5434 4580 2580 5168 4687 5494 4377 4224 4821 6389 5734 6284 5...
result:
ok 240 numbers
Test #10:
score: 0
Accepted
time: 181ms
memory: 14160kb
input:
100000 100000 17709 872080604 29908 948861030 31960 -909331019 4551 573019995 74654 -688106402 17784 -165486948 24765 -503004971 93138 -47580542 98455 -708200927 35979 -874695335 86738 -326977214 48335 912206161 13410 -654819759 52214 -917196936 97024 -728452010 40411 3245912 10276 885241981 59066 6...
output:
61740 40683 105833 105202 37101 111175 40683 260900 40683 106677 98202 29090 40683 100241 40683 111627 40683 179768 40683 40683 81997 40683 36117 106245 40683 236625 41443 40683 106611 121683 40683 57299 40683 93545 40683 44340 118578 40683 40683 27289 103670 40683 40683 40683 40683 42925 40683 4068...
result:
ok 100000 numbers
Test #11:
score: -100
Wrong Answer
time: 183ms
memory: 14208kb
input:
100000 100000 6073 685908938 16764 704624104 95954 273780301 19560 -659974636 69166 -6946088 17735 -461272926 72900 567789228 2748 -310095707 34051 643569128 49582 -223620070 28175 -390945828 55829 -361864174 41031 532714060 82113 403993012 25401 -160547950 11547 804155155 41120 -116232798 4795 7510...
output:
43092 40446 40446 47931 127194 40446 45880 9151 41302 37379 104574 124235 21603 105718 40446 40446 40446 92055 64633 97507 130625 48950 98322 44598 97514 40446 40446 40446 40446 104654 103020 40446 30511 176745 40446 62017 12307 40446 40446 40446 40446 40446 40446 62977 40446 40446 54007 40446 49588...
result:
wrong answer 8846th numbers differ - expected: '104135', found: '104134'