QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578001 | #9310. Permutation Counting 4 | ucup-team3160# | WA | 364ms | 18160kb | C++14 | 2.4kb | 2024-09-20 15:56:47 | 2024-09-20 15:56:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int N = 1000006, NN = N * 4;
int T, n;
struct segt
{
int mn[NN], to[NN];
ll lz[NN];
void build(int now, int l, int r)
{
mn[now] = lz[now] = 0;
to[now] = l;
if (l == r) return;
int mid = (l + r) >> 1;
build(now << 1, l, mid);
build(now << 1 | 1, mid + 1, r);
}
void up(int now)
{
if (mn[now << 1] < mn[now << 1 | 1])
to[now] = to[now << 1];
else
to[now] = to[now << 1 | 1];
mn[now] = min(mn[now << 1], mn[now << 1 | 1]);
}
void upd(int now, ll v)
{
lz[now] += v;
mn[now] += v;
}
void down(int now)
{
upd(now << 1, lz[now]);
upd(now << 1 | 1, lz[now]);
lz[now] = 0;
}
void ad1(int now, int l, int r, int ql, int qr, ll v)
{
if (ql <= l && qr >= r)
{
upd(now, v);
return;
}
if (ql > r || qr < l) return;
down(now);
int mid = (l + r) >> 1;
ad1(now << 1, l, mid, ql, qr, v);
ad1(now << 1 | 1, mid + 1, r, ql, qr, v);
up(now);
}
void ad2(int now, int l, int r, int p)
{
if (l == r)
{
lz[now] = mn[now] = INF;
return;
}
int mid = (l + r) >> 1;
down(now);
if (p <= mid) ad2(now << 1, l, mid, p);
else ad2(now << 1 | 1, mid + 1, r, p);
up(now);
}
int get(int now, int l, int r, int p)
{
if (l == r) return lz[now];
int mid = (l + r) >> 1;
down(now);
if (p <= mid) return get(now << 1, l, mid, p);
else return get(now << 1 | 1, mid + 1, r, p);
}
} t1, t2;
int l[N], r[N];
int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
t1.build(1, 1, n);
t2.build(1, 1, n);
int cnt = 0;
for (int i = 1; i <= n; i++)
{
scanf("%d%d", &l[i], &r[i]);
if (l[i] == 1)
{
t2.ad2(1, 1, n, r[i]);
cnt++;
}
if (l[i] - 1) t1.ad1(1, 1, n, l[i] - 1, l[i] - 1, i);
t1.ad1(1, 1, n, r[i], r[i], i);
if (l[i] - 1) t2.ad1(1, 1, n, l[i] - 1, l[i] - 1, 1);
t2.ad1(1, 1, n, r[i], r[i], 1);
}
bool ok = true;
for (int i = cnt + 1; i <= n; i++)
{
if (t2.mn[1] != 1)
{
//printf("%d %d\n", cnt, i);
ok = false;
break;
}
int t = t1.get(1, 1, n, t2.to[1]), tt = t2.to[1];
t1.ad1(1, 1, n, l[t] - 1, l[t] - 1, -t);
t1.ad1(1, 1, n, r[t], r[t], -t);
t2.ad1(1, 1, n, l[t] - 1, l[t] - 1, -1);
t2.ad1(1, 1, n, r[t], r[t], -1);
t2.ad2(1, 1, n, tt);
}
if (ok) printf("1\n");
else printf("0\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18140kb
input:
4 5 1 2 1 5 1 2 1 2 2 2 5 1 1 2 4 2 3 5 5 3 4 5 3 5 1 2 3 4 3 5 3 3 5 1 5 1 4 4 5 5 5 1 2
output:
0 1 0 0
result:
ok 4 tokens
Test #2:
score: -100
Wrong Answer
time: 364ms
memory: 18160kb
input:
66725 14 7 7 4 6 7 8 8 13 2 13 6 13 6 10 14 14 1 10 9 11 7 9 3 8 4 12 5 12 12 2 6 3 6 7 11 2 5 1 1 6 12 8 12 2 3 7 9 7 8 1 10 1 4 10 4 8 4 4 6 10 9 10 2 3 2 7 1 3 3 4 2 2 3 10 20 3 12 10 14 19 20 19 20 1 9 7 9 13 16 17 17 16 18 2 11 5 19 6 17 11 17 3 6 3 11 7 20 8 17 3 18 10 15 9 20 16 5 10 2 10 2 1...
output:
1 1 0 0 1 0 1 1 0 1 1 0 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 1 0 1 1 1 0 1 0 1 0 0 0 1 1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 0 0 1 0 1 1 ...
result:
wrong answer 14857th words differ - expected: '0', found: '1'