QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#339897 | #7440. rsxc | hos_lyric | RE | 1981ms | 340224kb | C++14 | 6.3kb | 2024-02-28 02:51:06 | 2024-02-28 02:51:08 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
// Manages linearly independent set in \F_2^n of max weight.
// S should be an integral type and support taking a bit and addition (^).
// T should support addition and comparison.
// invariant: ss[i] = 0 || 2^i <= ss[i] < 2^(i+1)
template <class S, class T> struct Basis {
int n;
vector<S> ss;
vector<T> ts;
T total;
Basis(int n_) : n(n_), ss(n, 0), ts(n, 0), total(0) {}
void add(S s, T t) {
total += t;
for (int i = n; --i >= 0; ) if (s >> i & 1) {
if (ss[i]) {
if (ts[i] < t) {
swap(ss[i], s);
swap(ts[i], t);
}
s ^= ss[i];
} else {
ss[i] = s;
ts[i] = t;
return;
}
}
total -= t;
}
};
////////////////////////////////////////////////////////////////////////////////
template <class T> void bAdd(vector<T> &bit, int pos, const T &val) {
const int bitN = bit.size();
for (int x = pos; x < bitN; x |= x + 1) bit[x] += val;
}
template <class T> T bSum(const vector<T> &bit, int pos) {
T ret = 0;
for (int x = pos; x > 0; x &= x - 1) ret += bit[x - 1];
return ret;
}
template <class T> T bSum(const vector<T> &bit, int pos0, int pos1) {
return bSum(bit, pos1) - bSum(bit, pos0);
}
// min pos s.t. pred(sum of [0, pos))
// assume pred(sum of [0, pos)) is non-decreasing
template <class T, class Pred>
int bBinarySearch(const vector<T> &bit, Pred pred) {
if (pred(T(0))) return 0;
const int bitLen = bit.size();
int pos = 0;
T sum = 0;
for (int e = 31 - __builtin_clz(bitLen); e >= 0; --e) {
const int x = (pos | 1 << e) - 1;
if (x < bitLen && !pred(sum + bit[x])) {
pos |= 1 << e;
sum += bit[x];
}
}
return pos + 1;
}
namespace seg {
using Value = Int;
constexpr int MAX_NUM_NODES = 20'000'010;
int n, id, ls[MAX_NUM_NODES], rs[MAX_NUM_NODES];
Value sum[MAX_NUM_NODES], lz[MAX_NUM_NODES];
void init(int n_) {
n = n_;
id = 0;
}
int newNode() {
assert(id < MAX_NUM_NODES);
const int u = id++;
ls[u] = rs[u] = -1;
sum[u] = lz[u] = Value();
return u;
}
int build(int l, int r) {
const int u = newNode();
if (l + 1 == r) return u;
const int mid = (l + r) / 2;
ls[u] = build(l, mid);
rs[u] = build(mid, r);
return u;
}
int add(int u, int l, int r, int a, int b, Value val) {
chmax(a, l);
chmin(b, r);
if (a >= b) return u;
const int v = newNode();
if (l == a && r == b) {
ls[v] = ls[u];
rs[v] = rs[u];
sum[v] = sum[u] + (b - a) * val;
lz[v] = lz[u] + val;
return v;
}
const int mid = (l + r) / 2;
ls[v] = add(ls[u], l, mid, a, b, val);
rs[v] = add(rs[u], mid, r, a, b, val);
sum[v] = sum[u] + (b - a) * val;
lz[v] = lz[u];
return v;
}
int add(int u, int a, int b, Value val) {
return add(u, 0, n, a, b, val);
}
Value get(int u, int l, int r, int a, int b) {
chmax(a, l);
chmin(b, r);
if (a >= b) return Value();
if (l == a && r == b) return sum[u];
const int mid = (l + r) / 2;
return (b - a) * lz[u] + get(ls[u], l, mid, a, b) + get(rs[u], mid, r, a, b);
}
Value get(int u, int a, int b) {
return get(u, 0, n, a, b);
}
void print(int u, int l, int r, int depth) {
cerr << string(2 * depth, ' ') << "[" << l << ", " << r << "): sum = " << sum[u] << ", lz = " << lz[u] << endl;
if (l + 1 < r) {
const int mid = (l + r) / 2;
print(ls[u], l, mid, depth + 1);
print(rs[u], mid, r, depth + 1);
}
}
void print(int u) {
print(u, 0, n, 0);
}
} // seg
constexpr int E = 30;
int N;
vector<int> segs(N + 1);
void init(int N_, int Q, vector<int> A) {
N = N_;
#ifdef LOCAL
cerr<<"[init] "<<N<<" "<<Q<<" "<<A<<endl;
#endif
seg::init(N + 1);
segs.assign(N + 1, -1);
segs[N] = seg::build(0, N + 1);
Basis<int, Int> basis(E);
map<int, int> app;
vector<int> bit(N, 0);
for (int i = N; --i >= 0; ) {
segs[i] = segs[i + 1];
basis.add(A[i], -i);
// cerr<<"ss = "<<basis.ss<<", ts = "<<basis.ts<<endl;
{
auto it = app.find(A[i]);
if (it != app.end()) {
bAdd(bit, it->second, -1);
}
app[A[i]] = i;
bAdd(bit, i, +1);
}
int jsLen = 0;
int js[E + 1];
js[jsLen++] = i;
for (int e = 0; e < E; ++e) if (basis.ss[e]) js[jsLen++] = -basis.ts[e];
sort(js, js + jsLen);
js[jsLen] = N;
// cerr<<"js = ";pv(js,js+(jsLen+1));
for (int d = 0; d < jsLen; ++d) {
// js[d] < r <= js[d + 1] ==> dim = d
if (js[d] < js[d + 1] && 1 << d <= (int)app.size()) {
const int pos = bBinarySearch(bit, [&](int sum) -> bool {
return (sum >= 1 << d);
});
// pos <= r <= js[d + 1]
if (pos <= js[d + 1]) {
#ifdef LOCAL
cerr<<i<<": ["<<pos<<", "<<js[d+1]<<"]"<<endl;
#endif
segs[i] = seg::add(segs[i], pos, js[d + 1] + 1, +1);
}
}
}
// seg::print(segs[i]);
}
}
Int solve(int L, int R) {
++R;
Int ans = 0;
ans += seg::get(segs[L], L, R + 1);
ans -= seg::get(segs[R], L, R + 1);
#ifdef LOCAL
cerr<<"[solve] "<<L<<" "<<R<<" = "<<ans<<endl;
#endif
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 12276kb
input:
1000 1000 12505600257298820166 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
2929934498377677671
result:
ok single line: '2929934498377677671'
Test #2:
score: 0
Accepted
time: 1981ms
memory: 313980kb
input:
600000 1000000 16250158766933054497 _VnMPQSoMkB2A`F6PR6Qe1<[<_U5[?L4[6R8VH`Ek7fMhm^:`C>?TMnJ]G[9Y<i6TcX`6W09N[:D[]MmW:3`@IhD6[ZIj[6nk9Ma=JW`LGn^`OTO0Mb`mc[53LM6X5eQ[3fD?6^Rfl`IAGBMd;cKMghBe`J\`66]OAX[0`j46K3KZ[fGiIM1THg`\nln`_=M@M2IoS[eZN=6H\ga[cOFO6N;d\`YhE2M4Ra;M7A@U`Z5bF6MfCh[`8Q_M;k01`V_Rb6AL3L[...
output:
10373212083833320350 8110969912885806797 1652287562556615452 7687084350761918228 15864205433837008504 11186966123302013273 6384724203398133399 88123121403580311 14593940278834881128 7750299022726819994 3665121167352871721 1584148493794015100 15979017321484609772 16972202416792440949 1160892536384682...
result:
ok 31 lines
Test #3:
score: 0
Accepted
time: 1704ms
memory: 340224kb
input:
600000 1000000 6574530603786764569 TM[JjTM[JjTM[JjTM[JjTM[Jj2390c2390c2390c2390c2390cOfXfdOfXfdOfXfdOfXfdOfXfd>n=dQ>n=dQ>n=dQ>n=dQ>n=dQC;\2VC;\2VC;\2VC;\2VC;\2VeE>H_eE>H_eE>H_eE>H_eE>H_XP_^XXP_^XXP_^XXP_^XXP_^XG44L5G44L5G44L5G44L5G44L5:aUZ2:aUZ2:aUZ2:aUZ2:aUZ2\_7`;\_7`;\_7`;\_7`;\_7`;aJV6<aJV6<aJV6<...
output:
4338573428526078476 10769352787453857139 15818674559617068677 17586345035624554490 13289697471106512844 18259160463921076240 8542047034291990047 7100488941136106084 5579512732443498040 6601016878751307742 16761282223118614617 7663574692222567505 10199185588650950166 17200790626052325761 935139697027...
result:
ok 31 lines
Test #4:
score: -100
Runtime Error
input:
600000 1000000 2415380648427590544 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...