QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#244683 | #6192. Interval Problem | Zeardoe | WA | 79ms | 29536kb | C++20 | 4.0kb | 2023-11-09 14:25:58 | 2023-11-09 14:25:58 |
Judging History
answer
/*
[templates]:
duipai
spjdp
compre
addhis
floor_sum
treedfs
matrix
network_flow
polynomial
lca
bitset
valuesgt
fenwick
erbitree
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//use ll instead of int.
#define f(i, a, b) for(int i = (a); i <= (b); i++)
#define cl(i, n) i.clear(),i.resize(n);
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e18;
//#define cerr if(false)cerr
//#define freopen if(false)freopen
mt19937 rng(time(0));
int rnd(int l, int r) {return rng() % (r-l+1) + l; }
#define watch(x) cerr << (#x) << ' '<<'i'<<'s'<<' ' << x << endl
void pofe(int number, int bitnum) {
string s; f(i, 0, bitnum) {s += char(number & 1) + '0'; number >>= 1; }
reverse(s.begin(), s.end()); cerr << s << endl;
return;
}
template <typename TYP> void cmax(TYP &x, TYP y) {if(x < y) x = y;}
template <typename TYP> void cmin(TYP &x, TYP y) {if(x > y) x = y;}
//调不出来给我对拍!
//use std::array.
const int N = 200000;
struct node {
int id, l, r;
}a[N + 10]; int n;
int ans[N + 10], sz[N + 10];
vector<int> son[N + 10]; int fa[N + 10]; int rgt[N + 10]; int id[N + 10];
int dep[N + 10]; int tmans = 0; int trsz[N + 10];
void dfs(int now) {
// cerr << "dfs: " << now << ", dep = " << dep[now] << endl;
tmans += dep[now]; trsz[now] = 1;
for(int i : son[now]) if(i != now) {
dep[i] = dep[now] + 1; dfs(i);
trsz[now] += trsz[i];
}
}
void solve2(int lo, int hi) {
int qlo = (lo - 1) * 2 + 1, qhi = hi * 2;
f(i, lo, hi) sz[i] = hi - lo;
// cerr << lo << " " << hi << endl;
f(i, lo, hi) son[i].clear();
f(i, qlo, qhi) rgt[i] = 0;
f(i, lo, hi) rgt[a[i].l] = a[i].r, id[a[i].r] = i;
// f(i, qlo, qhi) cerr << rgt[i] << " ";
// cerr << endl;
for(int i = qlo + 1; i <= qhi; i ++) cmax(rgt[i], rgt[i - 1]);
// f(i, qlo, qhi) cerr << rgt[i] << " ";
// cerr << endl;
f(i, lo, hi) {
int anc = id[rgt[a[i].r]];
son[anc].push_back(i);
fa[i] = anc;
}
// f(i, lo, hi) {
// cerr << "fa[" << i << "] = " << fa[i] << endl;
// }
int root = 0; tmans = 0;
f(i, lo, hi) if(fa[i] == i) root = i;
dep[root] = 1;
dfs(root);
// cerr << "tmans = " << tmans << endl;
vector<pii> rvec;
f(i, lo, hi) rvec.push_back({a[i].r, i});
sort(rvec.begin(), rvec.end(), greater<pii>());
// for(pii it : rvec) cerr << "r = " << it.first << ", id = " << it.second << endl ;
int j = 0;
for(int i = hi; i >= lo; i --) {
// cerr << "i = " << i << endl;
while(j < (int)rvec.size() && rvec[j].first >= a[i].l) {
// cerr << "del: " << j << endl;
tmans -= trsz[rvec[j].second]; j ++;
}
// cerr << "tmans = " << tmans << endl;
ans[a[i].id] += tmans;
}
}
void solve() {
sort(a + 1, a + n + 1, [=](node x, node y) {
return x.l < y.l;
});
int mxr = 0; int cur = 0;
f(i, 1, n + 1) {
if(i == n + 1 || mxr < a[i].l) {
if(cur != 0) solve2(cur, i - 1);
cur = i;
}
cmax(mxr, a[i].r);
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
//freopen();
//freopen();
//time_t start = clock();
//think twice,code once.
//think once,debug forever.
cin >> n;
f(i, 1, n) {
a[i].id = i;
cin >> a[i].l >> a[i].r;
}
solve();
f(i, 1, n) {
a[i].l = 2 * n + 1 - a[i].l;
a[i].r = 2 * n + 1 - a[i].r;
swap(a[i].l, a[i].r);
}
solve();
f(i, 1, n) cout << ans[i] + sz[i] << endl;
//time_t finish = clock();
//cout << "time used:" << (finish-start) * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 19872kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
7 5 4 5 5
result:
ok 5 number(s): "7 5 4 5 5"
Test #2:
score: -100
Wrong Answer
time: 79ms
memory: 29536kb
input:
200000 342504 342505 248314 248317 259328 259334 234817 234821 225726 225732 371424 371425 260562 260565 34752 34753 132098 132100 262130 262134 7254 7255 228491 228492 43488 43492 188408 188410 11691 11692 350334 350335 327350 327352 360684 360685 182051 182052 72131 72135 194666 194668 61303 61313...
output:
11 18 14 7 11 29 15 15 15 25 18 15 28 25 18 20 15 26 21 18 15 18 1 1 11 11 33 35 25 12 11 11 22 25 20 15 17 5 2 3 0 10 10 17 6 1 1 26 10 14 11 9 4 21 4 22 4 4 28 13 3 28 1 8 15 17 18 14 7 7 7 31 4 0 3 5 38 4 2 13 3 12 11 38 13 24 17 17 33 39 12 15 24 17 6 6 7 7 6 6 3 14 13 22 38 18 41 15 23 35 59 13...
result:
wrong answer 1st numbers differ - expected: '12', found: '11'