QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751037 | #5441. Quartz Collection | MiniLong | WA | 0ms | 38788kb | C++14 | 5.0kb | 2024-11-15 16:49:30 | 2024-11-15 16:49:30 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
#ifdef ONLINE_JUDGE
char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1e5 + 5, _ = 1e5;
ll n, m, a[N], b[N], cnt[N], cnt2[N];
namespace sgt{
struct node{
ll len, tot, sum[4];
//ABBA ABBA ABBA...
node(ll val = 0, ll num = 0){
len = num, sum[0] = sum[1] = sum[2] = sum[3] = 0;
tot = val * num;
if(num){
int t = num % 4;
sum[0] = (num / 4 * 2 + min(t, 1)) * val;
sum[1] = (num / 4 * 2 + max(0, t - 2)) * val;
sum[2] = (num / 4 * 2 + max(0, t - 1)) * val;
sum[3] = (num / 4 * 2 + min(t, 2)) * val;
}
}
node operator+(const node b)const{
node c; c.len = len + b.len, c.tot = tot + b.tot;
_rep(i, 0, 3) c.sum[i] = sum[i] + b.sum[(i + len) % 4];
return c;
}
}tr[N << 2];
#define ls x << 1
#define rs x << 1 | 1
void modify(int x, int l, int r, int p){
if(l == r) return tr[x] = node(p, cnt[p]), void();
int mid = l + r >> 1;
if(p <= mid) modify(ls, l, mid, p);
else modify(rs, mid + 1, r, p);
tr[x] = tr[rs] + tr[ls];
}
}
namespace sgt2{
struct node{
ll len, tot, sum[2];
//ABABABAB
node(ll val = 0, ll num = 0){
len = num, sum[0] = sum[1] = 0;
tot = val * num;
if(num){
int t = num % 2;
sum[0] = (num / 2 + t) * val;
sum[1] = (num / 2) * val;
}
}
node operator+(const node b)const{
node c; c.len = len + b.len, c.tot = tot + b.tot;
_rep(i, 0, 1) c.sum[i] = sum[i] + b.sum[(i + len) % 2];
return c;
}
}tr[N << 2];
#define ls x << 1
#define rs x << 1 | 1
void modify(int x, int l, int r, int p){
if(l == r) return tr[x] = node(p, cnt2[p]), void();
int mid = l + r >> 1;
if(p <= mid) modify(ls, l, mid, p);
else modify(rs, mid + 1, r, p);
tr[x] = tr[ls] + tr[rs];
}
}
ll sum;
ll calc(){
int cur = sgt::tr[1].len;
if(cur % 4 == 1 || cur % 4 == 3){
return sgt::tr[1].sum[0] - (sgt2::tr[1].tot - sgt2::tr[1].sum[0]);
}
return sgt::tr[1].sum[0] - sgt2::tr[1].sum[0];
}
void ins(int i, int op){
sum += b[i] * op;
if(a[i] >= 0) cnt[a[i]] += op, sgt::modify(1, 1, _, a[i]);
else cnt2[-a[i]] += op, sgt2::modify(1, 1, _, -a[i]);
}
int main(){
read(n, m);
_rep(i, 1, n){
ll x, y; read(x, y), a[i] = y - x, b[i] = y;
ins(i, 1);
}
writeln(sum - calc());
while(m--){
int t, x, y; read(t, x, y);
ins(t, -1), a[t] = y - x, b[t] = y, ins(t, 1);
writeln(sum - calc());
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 37032kb
input:
4 5 2 4 5 7 1 7 2 1 4 5 2 1 6 2 4 4 3 2 1 3 3 6 6
output:
13 14 15 14 10 13
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 37068kb
input:
1 1 1 1 1 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 38788kb
input:
100 100 6 7 100 8 5 61 5 75 59 65 51 47 83 37 34 54 87 46 4 26 21 87 12 97 86 68 60 11 62 76 14 83 29 31 91 62 57 80 47 75 85 97 62 77 91 86 14 25 48 77 83 65 39 61 78 77 45 46 90 74 100 91 86 98 55 5 84 42 91 69 100 4 74 98 60 37 75 44 41 12 15 34 36 1 99 16 7 87 36 26 79 42 41 84 17 98 72 16 38 55...
output:
5158 5104 5102 5050 5018 5048 5005 4981 4974 4991 4999 4966 4936 4925 4954 4920 4891 4841 4843 4828 4781 4764 4716 4668 4597 4671 4709 4739 4729 4737 4766 4787 4779 4755 4714 4685 4681 4735 4797 4831 4821 4821 4800 4806 4775 4796 4724 4721 4746 4699 4661 4609 4573 4610 4649 4628 4575 4571 4536 4550 ...
result:
wrong answer 1st numbers differ - expected: '5109', found: '5158'