QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#504046 | #2484. Screamers | PetroTarnavskyi | TL | 859ms | 3848kb | C++20 | 4.4kb | 2024-08-04 04:14:57 | 2024-08-04 04:14:57 |
Judging History
answer
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
typedef struct Snode* sn;
struct Snode
{
sn p, c[2]; // parent, children
bool rev = false; // subtree flipped or not
int val, sz; // value in node, # nodes in splay subtree (as cnt in treap)
int sub, vsub = 0; // vsub stores sum of virtual children
Snode(int _val): val(_val)
{
p = c[0] = c[1] = 0;
upd();
}
friend int getSz(sn x)
{
return x ? x->sz : 0;
}
friend int getSub(sn x)
{
return x ? x->sub : 0;
}
void push()
{
if (!rev)
return;
swap(c[0], c[1]);
rev = false;
FOR (i, 0, 2)
if (c[i])
c[i]->rev ^= 1;
}
void upd()
{
FOR (i, 0, 2)
if (c[i])
c[i]->push();
sz = 1 + getSz(c[0]) + getSz(c[1]);
sub = 1 + getSub(c[0]) + getSub(c[1]) + vsub;
}
//////// SPLAY TREE OPERATIONS
int dir()
{
if (!p) return -2;
FOR (i, 0, 2)
if (p->c[i] == this)
return i;
return -1; // p is path-parent pointer
} // -> not in current splay tree
// test if root of current splay tree
bool isRoot()
{
return dir() < 0;
}
friend void setLink(sn x, sn y, int d)
{
if (y)
y->p = x;
if (d >= 0)
x->c[d] = y;
}
// assume p and p->p are propagated
void rot()
{
assert(!isRoot());
int x = dir();
sn pa = p;
setLink(pa->p, this, pa->dir());
setLink(pa, c[x ^ 1], x);
setLink(this, pa, x ^ 1);
pa->upd();
}
void splay()
{
while (!isRoot() && !p->isRoot())
{
p->p->push();
p->push();
push();
dir() == p->dir() ? p->rot() : rot();
rot();
}
if (!isRoot())
p->push(), push(), rot();
push();
upd();
}
//////// BASE OPERATIONS
// bring this to top of tree, propagate
void access()
{
for (sn v = this, pre = 0; v; v = v->p)
{
v->splay(); // now switch virtual children
if (pre)
v->vsub -= pre->sub;
if (v->c[1])
v->vsub += v->c[1]->sub;
v->c[1] = pre;
v->upd();
pre = v;
}
splay();
assert(!c[1]); // right subtree is empty
}
void makeRoot()
{
access();
rev ^= 1;
access();
assert(!c[0] && !c[1]);
}
//////// QUERIES
friend sn lca(sn x, sn y)
{
if (x == y)
return x;
x->access();
y->access();
if (!x->p)
return 0;
x->splay();
return x->p ? x->p : x; // y was below x in latter case
} // access at y did not affect x -> not connected
friend bool connected(sn x, sn y)
{
return lca(x,y);
}
// # nodes above
int distRoot()
{
access();
return getSz(c[0]);
}
sn getRoot()
{ // get root of LCT component
access();
sn a = this;
while (a->c[0])
{
a = a->c[0];
a->push();
}
a->access();
return a;
}
//////// MODIFICATIONS
void set(int v)
{
access();
val = v;
upd();
}
friend void link(sn x, sn y)
{
assert(!connected(x, y));
y->makeRoot();
x->access();
setLink(y, x, 0);
y->upd();
}
// cut y from its parent
friend void cut(sn y)
{
y->access();
assert(y->c[0]);
y->c[0]->p = 0;
y->c[0] = 0;
y->upd();
}
// if x, y adj in tree
friend void cut(sn x, sn y)
{
x->makeRoot();
y->access();
assert(y->c[0] == x && !x->c[0] && !x->c[1]);
cut(y);
}
};
const int N = 100'447;
sn LCT[N];
VI a;
LL f(int l, int r)
{
LL sum = 0;
FOR (i, l, r)
sum += min(r, a[i]) - i;
return sum;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
FOR (i, 0, n) LCT[i] = new Snode(i);
queue<PII> q;
a = VI(m, m);
int idx = 0;
FOR (i, 0, m)
{
int u, v;
cin >> u >> v;
u--, v--;
q.push({u, v});
while (connected(LCT[u], LCT[v]))
{
auto [u1, v1] = q.front();
q.pop();
a[idx++] = i;
cut(LCT[u1], LCT[v1]);
}
link(LCT[u], LCT[v]);
}
int qq;
cin >> qq;
FOR (i, 0, qq)
{
int l, r;
cin >> l >> r;
l--;
cout << f(l, r) << '\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
4 6 1 2 2 3 1 3 1 4 3 4 2 4 4 1 1 1 3 2 4 1 6
output:
1 5 6 13
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
3 3 1 2 1 3 2 3 6 1 1 1 2 1 3 2 2 2 3 3 3
output:
1 3 5 1 3 1
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
4 6 1 2 1 3 1 4 2 3 2 4 3 4 21 1 1 1 2 1 3 1 4 1 5 1 6 2 2 2 3 2 4 2 5 2 6 3 3 3 4 3 5 3 6 4 4 4 5 4 6 5 5 5 6 6 6
output:
1 3 6 9 12 14 1 3 6 9 11 1 3 6 8 1 3 5 1 3 1
result:
ok 21 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
5 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5 55 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 4 4 4 5 4 6 4 7 4 8 4 9 4 10 5 5 5 6 5 7 5 8 5 9 5 10 6 6 6 7 6 8 6 9 6 10 7 7 7 8 7 9 7 10 8 8 8 9 8 10 9 9 9 10 10 10
output:
1 3 6 10 14 18 22 25 28 30 1 3 6 10 14 18 21 24 26 1 3 6 10 14 17 20 22 1 3 6 10 13 16 18 1 3 6 9 12 14 1 3 6 9 11 1 3 6 8 1 3 5 1 3 1
result:
ok 55 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
6 15 1 2 1 3 1 4 1 5 1 6 2 3 2 4 2 5 2 6 3 4 3 5 3 6 4 5 4 6 5 6 120 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 3 3 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 4 4 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4...
output:
1 3 6 10 15 20 25 30 35 39 43 47 50 53 55 1 3 6 10 15 20 25 30 34 38 42 45 48 50 1 3 6 10 15 20 25 29 33 37 40 43 45 1 3 6 10 15 20 24 28 32 35 38 40 1 3 6 10 15 19 23 27 30 33 35 1 3 6 10 14 18 22 25 28 30 1 3 6 10 14 18 21 24 26 1 3 6 10 14 17 20 22 1 3 6 10 13 16 18 1 3 6 9 12 14 1 3 6 9 11 1 3 6...
result:
ok 120 lines
Test #6:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
7 21 1 2 1 3 1 4 1 5 1 6 1 7 2 3 2 4 2 5 2 6 2 7 3 4 3 5 3 6 3 7 4 5 4 6 4 7 5 6 5 7 6 7 231 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 3 3 3 4 3 5 3 6 3 7...
output:
1 3 6 10 15 21 27 33 39 45 51 56 61 66 71 75 79 83 86 89 91 1 3 6 10 15 21 27 33 39 45 50 55 60 65 69 73 77 80 83 85 1 3 6 10 15 21 27 33 39 44 49 54 59 63 67 71 74 77 79 1 3 6 10 15 21 27 33 38 43 48 53 57 61 65 68 71 73 1 3 6 10 15 21 27 32 37 42 47 51 55 59 62 65 67 1 3 6 10 15 21 26 31 36 41 45 ...
result:
ok 231 lines
Test #7:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
8 28 1 2 1 3 1 4 1 5 1 6 1 7 1 8 2 3 2 4 2 5 2 6 2 7 2 8 3 4 3 5 3 6 3 7 3 8 4 5 4 6 4 7 4 8 5 6 5 7 5 8 6 7 6 8 7 8 406 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2...
output:
1 3 6 10 15 21 28 35 42 49 56 63 70 76 82 88 94 100 105 110 115 120 124 128 132 135 138 140 1 3 6 10 15 21 28 35 42 49 56 63 69 75 81 87 93 98 103 108 113 117 121 125 128 131 133 1 3 6 10 15 21 28 35 42 49 56 62 68 74 80 86 91 96 101 106 110 114 118 121 124 126 1 3 6 10 15 21 28 35 42 49 55 61 67 73...
result:
ok 406 lines
Test #8:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
9 36 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 4 3 5 3 6 3 7 3 8 3 9 4 5 4 6 4 7 4 8 4 9 5 6 5 7 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9 666 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1...
output:
1 3 6 10 15 21 28 36 44 52 60 68 76 84 92 99 106 113 120 127 134 140 146 152 158 164 169 174 179 184 188 192 196 199 202 204 1 3 6 10 15 21 28 36 44 52 60 68 76 84 91 98 105 112 119 126 132 138 144 150 156 161 166 171 176 180 184 188 191 194 196 1 3 6 10 15 21 28 36 44 52 60 68 76 83 90 97 104 111 1...
result:
ok 666 lines
Test #9:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
10 45 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 3 4 3 5 3 6 3 7 3 8 3 9 3 10 4 5 4 6 4 7 4 8 4 9 4 10 5 6 5 7 5 8 5 9 5 10 6 7 6 8 6 9 6 10 7 8 7 9 7 10 8 9 8 10 9 10 1035 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22...
output:
1 3 6 10 15 21 28 36 45 54 63 72 81 90 99 108 117 125 133 141 149 157 165 173 180 187 194 201 208 215 221 227 233 239 245 250 255 260 265 269 273 277 280 283 285 1 3 6 10 15 21 28 36 45 54 63 72 81 90 99 108 116 124 132 140 148 156 164 171 178 185 192 199 206 212 218 224 230 236 241 246 251 256 260 ...
result:
ok 1035 lines
Test #10:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
100 100 31 92 16 73 42 62 11 38 42 99 81 95 27 97 11 89 6 60 15 85 14 27 55 84 42 88 38 47 20 54 52 61 55 79 77 95 57 92 61 95 63 81 8 38 67 91 8 13 27 59 27 41 15 37 15 46 46 100 21 88 19 47 76 98 13 29 4 72 12 97 4 30 13 53 32 84 23 93 66 69 54 74 77 95 77 92 80 92 44 62 19 64 4 75 30 51 37 60 70 ...
output:
595 595 171 171 378 630 231 153 3374 36 435 1804 1880 900 253 351 78 2227 36 1 2841 351 435 1225 1886 2725 990 2435 105 435 1484 45 45 1293 1653 3 1931 66 190 2900 171 2144 378 351 2115 406 300 900 1275 595 171 1880 378 690 861 91 2835 2473 120 1431 1569 1239 1587 1534 210 435 465 66 15 136 120 1326...
result:
ok 100 lines
Test #11:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
100 100 24 63 17 51 60 76 40 61 3 7 44 80 50 86 61 77 91 97 17 61 15 42 39 100 40 56 32 53 12 85 17 31 84 98 39 97 8 27 15 99 39 65 46 77 6 18 23 39 17 37 49 67 36 84 13 18 73 77 15 27 51 57 13 49 36 41 16 35 3 9 69 78 23 73 4 66 12 20 11 70 27 58 38 98 44 69 71 75 35 39 68 76 28 33 37 66 72 81 36 9...
output:
2187 1485 939 528 1176 2397 231 1378 630 2278 1035 55 1485 2760 378 2211 21 300 66 2701 253 1275 3191 190 703 6 10 2004 2285 3216 699 15 210 10 28 153 15 861 356 120 153 171 2908 1128 3306 450 1770 3088 630 1425 28 231 66 105 2346 276 1891 149 105 36 66 55 2465 468 666 465 2145 946 595 10 1945 210 2...
result:
ok 100 lines
Test #12:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
100 100 12 14 2 19 83 91 49 64 17 88 9 10 23 70 30 100 52 83 72 84 17 35 47 62 38 55 18 46 74 91 4 11 11 37 22 79 9 15 9 48 28 30 42 51 78 100 59 98 14 61 65 85 1 10 32 41 30 69 27 32 91 98 81 98 13 62 43 76 21 33 24 41 59 98 11 97 37 94 82 87 9 31 2 40 45 89 49 88 22 37 36 73 6 96 50 91 20 97 16 95...
output:
300 446 91 66 1077 609 822 1206 21 1396 325 1611 171 3 15 3 1147 78 3 66 752 527 1402 28 666 541 45 21 623 1683 1378 153 21 1050 1468 287 798 515 1548 654 879 136 435 276 153 1968 255 21 714 15 1496 91 1960 276 458 442 973 66 435 918 478 351 91 342 612 55 1 91 28 153 1266 10 1336 561 1380 253 6 136 ...
result:
ok 100 lines
Test #13:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
100 100 41 90 17 72 51 92 11 22 33 47 33 92 2 58 42 95 14 94 28 31 13 66 45 71 7 44 87 91 82 98 18 23 55 74 7 58 59 88 7 95 57 76 7 97 65 86 61 67 4 71 3 12 16 18 44 55 59 65 34 61 31 90 1 28 50 74 78 90 8 19 9 48 16 95 20 81 78 87 23 91 9 20 6 37 58 83 62 86 36 91 21 55 30 88 5 8 47 56 4 5 34 71 34...
output:
15 2032 1480 1128 171 78 3033 1275 435 91 561 820 561 36 36 1810 28 1326 406 1077 1225 21 171 1 406 45 1378 190 66 1081 1980 28 136 6 1275 946 3 253 1686 120 78 946 10 45 741 120 45 231 438 1572 1225 15 1326 28 105 820 36 2413 10 435 210 21 10 820 435 2508 28 15 2694 6 465 190 2413 2319 15 6 10 3295...
result:
ok 100 lines
Test #14:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
100 100 9 14 28 88 35 36 63 74 18 38 40 44 38 61 16 94 19 23 17 74 94 95 49 59 25 86 41 42 80 82 74 79 38 49 19 28 1 73 8 24 13 32 15 29 68 73 40 73 64 85 30 56 36 40 30 98 3 64 12 45 72 87 9 66 77 81 74 99 14 30 61 63 48 58 30 78 28 56 52 68 78 82 11 82 36 93 4 83 19 27 1 14 8 81 22 68 43 87 30 62 ...
output:
886 225 28 351 435 190 630 496 528 2013 6 10 36 3 630 45 276 1143 120 351 325 231 136 741 697 291 6 496 78 325 15 36 1302 120 3 3 1 2481 528 1176 561 6 561 276 465 435 28 190 136 613 961 55 45 2984 3 78 2152 6 1033 1281 171 253 1927 1 528 520 2798 528 1095 78 153 21 903 91 1326 325 630 2823 1705 138...
result:
ok 100 lines
Test #15:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
100 100 6 72 30 62 75 98 40 45 31 61 13 20 46 48 31 33 57 76 25 97 9 47 45 89 66 88 60 71 10 81 12 61 19 96 16 34 48 79 5 92 7 69 31 42 80 81 38 86 47 58 31 33 20 72 4 37 11 29 14 90 89 100 94 96 27 44 42 46 63 65 44 88 56 68 48 77 47 82 23 54 29 35 42 90 7 38 17 33 76 90 42 78 29 42 23 43 77 93 9 9...
output:
190 561 66 171 697 210 1551 630 36 3191 2071 78 990 15 1431 36 276 693 136 171 1657 837 1663 1378 21 406 136 3 171 528 2883 28 136 378 10 1653 325 2031 91 3471 171 45 1431 231 66 171 903 939 1 667 1228 695 1135 528 378 465 1830 1786 15 1566 120 2128 6 703 3026 36 435 2149 66 21 1128 630 3 10 21 1176...
result:
ok 100 lines
Test #16:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
100 100 61 82 16 58 15 70 47 48 11 56 71 84 15 90 37 96 60 70 2 50 48 91 31 45 3 91 15 21 35 51 12 37 47 71 41 73 24 30 16 23 45 49 18 21 21 41 2 43 52 61 25 65 18 93 75 83 1 66 14 35 47 90 66 95 18 97 19 33 66 91 21 53 52 64 35 52 40 60 32 41 43 84 5 35 4 84 2 61 37 97 85 90 4 94 10 92 36 85 29 73 ...
output:
1348 741 1275 861 1275 171 703 2001 1685 435 66 276 1266 2613 561 2275 1413 3 561 666 1863 66 1011 78 1540 465 903 741 91 1081 435 21 1691 1063 528 406 1898 3 820 1128 1911 861 231 66 66 36 1176 528 136 1253 105 3 120 3142 2331 28 1225 91 91 2521 435 21 15 1985 3202 899 10 528 990 903 55 190 300 465...
result:
ok 100 lines
Test #17:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
100 100 40 66 7 28 16 78 40 66 29 88 25 46 55 76 8 53 54 98 49 82 4 28 30 71 33 37 75 87 51 66 17 28 75 84 71 73 40 81 40 86 15 96 47 61 30 96 17 42 23 40 73 91 48 65 6 13 12 88 83 100 40 62 76 94 27 96 13 52 15 37 64 84 24 61 24 33 51 83 30 44 9 70 41 47 41 86 33 100 79 97 10 14 37 63 92 97 63 85 2...
output:
253 406 120 10 1302 3069 66 105 780 1847 3 1 3 1711 253 2320 1378 28 1453 10 741 300 561 1 36 1791 276 1081 1176 36 66 171 276 1176 465 2484 66 3403 2453 741 325 2516 3 120 1445 666 2436 210 2985 190 136 2206 561 1162 780 36 231 1948 1794 36 2344 325 136 190 780 153 303 1792 253 21 990 231 231 2493 ...
result:
ok 100 lines
Test #18:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
100 100 10 49 48 93 49 51 24 61 6 11 28 76 8 98 3 51 67 95 14 76 10 97 21 72 40 57 34 87 37 84 17 19 3 63 27 63 55 61 16 65 35 76 20 93 41 76 7 86 37 53 43 54 22 71 42 74 17 29 2 17 19 39 48 63 28 88 13 58 52 80 16 29 11 94 53 97 58 74 19 60 3 9 45 87 74 96 17 27 43 52 17 53 36 76 2 72 52 82 10 30 6...
output:
136 105 253 190 2038 3 45 3395 1 1766 1445 2360 190 136 1953 15 666 325 55 15 231 3 28 1326 820 666 946 3 91 1035 78 55 1169 78 1225 1 1378 820 136 6 1904 666 861 325 10 3 171 3 231 595 300 1946 1128 45 36 465 153 1176 1176 91 276 136 3 2319 21 325 300 820 3 1176 231 2584 276 15 171 406 780 231 741 ...
result:
ok 100 lines
Test #19:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
100 100 31 48 24 36 47 82 85 100 46 59 66 94 15 64 17 83 21 37 35 42 47 86 21 41 31 44 31 41 10 70 16 50 85 94 33 61 39 54 39 92 6 67 83 91 58 98 56 59 22 89 9 68 30 80 55 64 78 100 54 86 4 10 14 43 44 67 41 93 19 79 31 57 18 47 9 64 41 90 66 95 7 44 61 80 33 70 18 31 36 70 14 94 23 96 16 25 12 55 3...
output:
91 351 1096 630 6 153 231 741 45 780 1936 2076 45 666 78 465 780 120 3601 45 595 1378 15 45 1128 231 2010 45 36 595 465 1971 1441 1726 1275 351 2076 36 903 190 120 1821 253 3265 36 3 666 10 253 1947 1378 300 1957 1528 1683 231 1128 171 990 3 1176 666 741 1791 171 91 1 351 378 630 300 1582 171 105 14...
result:
ok 100 lines
Test #20:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
20 190 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14...
output:
366 1698 762 714 3 758 550 78 2043 578 563 967 1720 446 377 102 6 1325 268 1274 342 1870 45 501 1572 362 234 217 104 767 316 158 28 1105 1820 1038 1216 415 2133 425 1304 349 351 713 153 1432 383 1150 1468 435 128 868 748 85 231 126 909 349 10 1984 2257 21 945 78 1345 560 791 1058 297 1287 359 167 16...
result:
ok 1000 lines
Test #21:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
40 780 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 2...
output:
2946 105 2899 16361 16361 6279 12175 210 3269 4217 10048 2458 13937 1430 4264 10045 4016 10871 13610 7122 194 10368 9897 8788 15953 11088 8195 55 6025 15598 10513 5429 5840 10269 17826 16840 742 3503 3131 2151 330 1951 322 16701 280 3249 9234 546 370 19110 3757 12510 5612 6065 13805 3547 4745 19656 ...
result:
ok 1000 lines
Test #22:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
60 1770 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 2 3 2...
output:
44968 8392 23706 20840 23382 51134 43582 11840 57240 8644 153 18113 3079 14956 22636 31614 30470 18876 29933 39685 26192 17709 105 44910 29458 1862 6457 16016 17926 41608 51910 6976 41011 11169 7628 41983 40064 11617 8558 37257 14417 54614 6256 4064 62134 41770 2768 31963 15953 32057 45404 16674 902...
result:
ok 1000 lines
Test #23:
score: 0
Accepted
time: 2ms
memory: 3584kb
input:
80 3160 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 ...
output:
29685 148940 46252 528 7710 105429 162846 38868 37493 16794 17670 34300 91700 1258 106466 48926 4776 706 143150 161819 4251 49017 71884 351 54407 146981 117700 134679 127703 85399 93121 131348 15906 11566 14598 13311 155434 73354 37856 68452 11198 46333 25057 4922 58558 48727 18038 68056 68562 80144...
result:
ok 1000 lines
Test #24:
score: 0
Accepted
time: 65ms
memory: 3572kb
input:
100 4950 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61...
output:
200805 78228 35308 101566 193878 208229 41972 69271 102295 32662 215084 129422 56761 142165 13454 117597 288754 14448 67545 54710 102255 9550 167479 137202 28041 39705 70625 174619 6562 76778 91153 7509 218684 15230 40366 60710 7704 3828 174052 21271 206436 60410 6822 158216 217634 98370 115958 1616...
result:
ok 100000 lines
Test #25:
score: 0
Accepted
time: 221ms
memory: 3700kb
input:
200 19900 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 6...
output:
554732 1029283 2446815 1284896 386106 1976156 65799 614017 304900 96765 1647137 2443454 1396111 244344 804657 2398442 22596 56594 231861 733999 1529049 866152 700774 1482142 813216 12930 1290419 218094 1181498 898219 2274283 98070 1107356 1691327 521030 252057 1960512 914765 521804 1001994 1205622 1...
result:
ok 100000 lines
Test #26:
score: 0
Accepted
time: 487ms
memory: 3584kb
input:
300 44850 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 6...
output:
1651512 3971957 3647411 2746873 11935 2044865 3068063 4038220 4415924 3131755 4030280 7260274 651554 6653849 1859737 5454728 724710 6406540 4743858 6293993 3477629 3920931 1862611 809695 4940658 4280975 101626 6112459 165094 1894639 6005868 310957 6323951 1309398 2634920 1292515 8335634 2339534 2153...
result:
ok 100000 lines
Test #27:
score: 0
Accepted
time: 859ms
memory: 3580kb
input:
400 79800 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 6...
output:
13665992 18970874 2765411 641593 17366512 11842444 1350804 2752259 8262610 8375659 62872 4061346 9661849 3726202 10977922 13729769 7342746 266436 2517029 17558978 4390030 2850181 308730 8960277 8596255 4589033 1955290 7764510 4460096 9752665 1620110 5828355 3595757 15491909 3255877 7433669 12612914 ...
result:
ok 100000 lines
Test #28:
score: -100
Time Limit Exceeded
input:
100000 99999 1 2 1 3 2 4 1 5 3 6 4 7 4 8 7 9 2 10 8 11 2 12 10 13 12 14 14 15 7 16 4 17 9 18 2 19 19 20 5 21 3 22 21 23 22 24 23 25 23 26 18 27 17 28 15 29 8 30 30 31 6 32 13 33 33 34 27 35 5 36 3 37 11 38 19 39 29 40 14 41 31 42 10 43 42 44 13 45 23 46 19 47 29 48 32 49 23 50 32 51 47 52 52 53 36 5...
output:
217559370 9058896 772972221 58574076 391062561 2901505753 61067826 2944935885 55067265 310590426 82799146 5653203 229440331 80994628 1883537376 126667486 864344253 535250121 179409153 1200965545 402753 2241903 1294260003 359106600 100642578 980159950 3256688865 1725751875 2265256 1272777831 12584893...