Submission #561168
Source Code Expand
#include <iostream>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
struct AA {
using NP = AA*;
ll sm;
bool lz;
NP l, r;
ll sz; int lv;
bool isL; // is last
AA(ll sz, bool lz) : l(nullptr), r(nullptr), sz(sz), lv(0), isL(true) {
if (lz) {
sm = 0;
} else {
sm = sz;
}
this->lz = lz;
}
AA(NP l, NP r, int lv) : l(l), r(r), lv(lv), isL(false) {
lz = false;
update();
}
void update() {
assert(!lz);
sz = l->sz + r->sz;
sm = l->sm + r->sm;
}
void push() {
if (lz) {
if (l->sz) {
l->lzdata();
}
if (r->sz) {
r->lzdata();
}
lz = false;
}
}
void lzdata() {
sm = 0;
lz = true;
}
static NP skew(NP n) {
if (n->l == nullptr || n->lv != n->l->lv) return n;
NP L = n->l;
n->l = L->r;
n->update();
L->r = n;
L->update();
return L;
}
static NP pull(NP n) {
if (n->r == nullptr || n->lv != n->r->lv) return n;
if (n->r->r == nullptr || n->lv != n->r->r->lv) return n;
NP R = n->r;
n->r = R->l;
n->update();
R->l = n;
R->lv++;
R->update();
return R;
}
static NP inscut(NP n, ll k) {
if (k == 0 || k == n->sz) return n;
if (n->isL) {
return new AA(new AA(k, n->lz), new AA(n->sz - k, n->lz), 1);
}
n->push();
if (k <= n->l->sz) {
n->l = inscut(n->l, k);
n->update();
return pull(skew(n));
} else {
n->r = inscut(n->r, k - n->l->sz);
n->update();
return pull(skew(n));
}
}
static ll get(NP n, ll a, ll b) {
if (b <= 0 || n->sz <= a) return 0;
if (a <= 0 && n->sz <= b) return n->sm;
n->push();
return get(n->l, a, b) + get(n->r, a - n->l->sz, b - n->l->sz);
}
static void set(NP n, ll a, ll b) {
if (b <= 0 || n->sz <= a) return;
if (a <= 0 && n->sz <= b) {
n->lzdata();
return;
}
assert(n->isL == false);
set(n->l, a, b);
set(n->r, a - n->l->sz, b - n->l->sz);
n->update();
}
static ll sea(NP n, ll x) {
assert(x < n->sm);
if (n->isL) {
assert(!n->lz);
return x;
}
n->push();
if (x < n->l->sm) {
return sea(n->l, x);
} else {
return n->l->sz + sea(n->r, x - n->l->sm);
}
}
};
int main() {
int n;
scanf("%d", &n);
AA* t2 = new AA(1e18 + 1e17, false);
for (int i = 0; i < n; i++) {
ll s, c;
scanf("%lld %lld", &s, &c);
t2 = AA::inscut(t2, 0);
t2 = AA::inscut(t2, s);
ll fi = AA::get(t2, 0, s);
ll l = AA::sea(t2, c+fi-1);
t2 = AA::inscut(t2, s);
t2 = AA::inscut(t2, l+1);
AA::set(t2, s, l+1);
printf("%lld\n", l);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Squares, Pieces and Coloring |
User |
yosupo |
Language |
C++11 (GCC 4.9.2) |
Score |
100 |
Code Size |
2672 Byte |
Status |
AC |
Exec Time |
583 ms |
Memory |
38300 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:120:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:124:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &s, &c);
^
Judge Result
Set Name |
Sample |
Dataset1 |
Dataset2 |
Dataset3 |
Score / Max Score |
0 / 0 |
35 / 35 |
40 / 40 |
25 / 25 |
Status |
|
|
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt, sample-03.txt |
Dataset1 |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt |
Dataset2 |
sample-01.txt, sample-02.txt, sample-03.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt |
Dataset3 |
sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, 03-09.txt, 03-10.txt, 03-11.txt, 03-12.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
265 ms |
19456 KB |
01-02.txt |
AC |
403 ms |
19436 KB |
01-03.txt |
AC |
366 ms |
19488 KB |
01-04.txt |
AC |
218 ms |
19488 KB |
01-05.txt |
AC |
26 ms |
800 KB |
01-06.txt |
AC |
28 ms |
924 KB |
01-07.txt |
AC |
32 ms |
1176 KB |
01-08.txt |
AC |
59 ms |
4260 KB |
01-09.txt |
AC |
254 ms |
17180 KB |
02-01.txt |
AC |
28 ms |
928 KB |
02-02.txt |
AC |
28 ms |
1060 KB |
02-03.txt |
AC |
31 ms |
1052 KB |
02-04.txt |
AC |
28 ms |
1056 KB |
02-05.txt |
AC |
27 ms |
1052 KB |
02-06.txt |
AC |
29 ms |
1056 KB |
02-07.txt |
AC |
28 ms |
1176 KB |
02-08.txt |
AC |
29 ms |
1092 KB |
02-09.txt |
AC |
27 ms |
1088 KB |
02-10.txt |
AC |
26 ms |
920 KB |
02-11.txt |
AC |
24 ms |
808 KB |
02-12.txt |
AC |
27 ms |
1064 KB |
03-01.txt |
AC |
420 ms |
19504 KB |
03-02.txt |
AC |
564 ms |
38240 KB |
03-03.txt |
AC |
579 ms |
38004 KB |
03-04.txt |
AC |
390 ms |
19440 KB |
03-05.txt |
AC |
458 ms |
38272 KB |
03-06.txt |
AC |
533 ms |
38276 KB |
03-07.txt |
AC |
508 ms |
38244 KB |
03-08.txt |
AC |
452 ms |
38232 KB |
03-09.txt |
AC |
452 ms |
37812 KB |
03-10.txt |
AC |
68 ms |
4516 KB |
03-11.txt |
AC |
573 ms |
38300 KB |
03-12.txt |
AC |
583 ms |
38176 KB |
sample-01.txt |
AC |
26 ms |
920 KB |
sample-02.txt |
AC |
26 ms |
924 KB |
sample-03.txt |
AC |
24 ms |
920 KB |