Submission #1145861
Source Code Expand
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }
unsigned xor128() {
static unsigned x = 123456789, y = 362436069, z = random_device{}(), w = random_device{}();
unsigned t = x ^ (x << 11);
x = y; y = z; z = w;
return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}
struct Node {
static Node nullNode;
static int K;
unsigned priority;
Node *left, *right;
int size;
int pos;
int consume;
long long produce;
long long sumBase;
long long sumMaxAdd;
bool isNull() const { return priority == 0; }
Node *set(int D, int A) {
*this = nullNode;
do priority = xor128(); while (priority == 0);
pos = D;
consume = A;
return update();
}
inline Node *update() {
assert(!isNull());
size = left->size + 1 + right->size;
produce = left->produce;
sumBase = left->sumBase;
sumMaxAdd = left->sumMaxAdd;
if (!left->isNull()) {
produce += (ll)(pos - left->pos) * K;
}
{
ll t = min((ll)consume, produce);
produce -= t;
sumBase += t;
sumMaxAdd += consume - t;
}
if (!right->isNull()) {
produce += (ll)(right->pos - pos) * K;
}
{
ll t = min((ll)right->sumMaxAdd, produce);
produce -= t;
sumBase += t;
sumMaxAdd += right->sumMaxAdd - t;
}
sumBase += right->sumBase;
produce += right->produce;
return this;
}
inline void propagate() {
}
inline Node *linkl(Node *c) {
left = c;
return update();
}
inline Node *linkr(Node *c) {
right = c;
return update();
}
inline Node *linklr(Node *l, Node *r) {
left = l, right = r;
return update();
}
inline Node *linkl2(Node *c) {
if (priority >= c->priority)
return linkl(c);
else
return c->linkr(linkl(c->right));
}
inline Node *linkr2(Node *c) {
if (priority >= c->priority)
return linkr(c);
else
return c->linkl(linkr(c->left));
}
};
int Node::K;
Node Node::nullNode = {
0,
&nullNode, &nullNode,
0, -1, 0,
0, 0, 0
};
struct RBST {
typedef Node *Ref;
static Ref join(Ref l, Ref r) {
if (l->isNull()) return r;
if (r->isNull()) return l;
if (l->priority >= r->priority) {
l->propagate();
return l->linkr(join(l->right, r));
}
else {
r->propagate();
return r->linkl(join(l, r->left));
}
}
typedef pair<Ref, Ref> RefPair;
static RefPair splitPos(Ref t, int pos) {
if (t->isNull()) return RefPair(&Node::nullNode, &Node::nullNode);
t->propagate();
if (pos <= t->pos) {
RefPair p = splitPos(t->left, pos);
return RefPair(p.first, t->linkl(p.second));
}
else {
RefPair p = splitPos(t->right, pos);
return RefPair(t->linkr(p.first), p.second);
}
}
static Ref insertPos(Ref t, Ref n) {
if (t->isNull()) return n;
t->propagate();
if (n->pos <= t->pos)
return t->linkl2(insertPos(t->left, n));
else
return t->linkr2(insertPos(t->right, n));
}
static void decompose(Ref t, vector<Ref> &res) {
if (t->isNull()) return;
t->propagate();
Ref l = t->left, r = t->right;
t->left = t->right = &Node::nullNode;
decompose(l, res);
res.push_back(t);
decompose(r, res);
}
};
int main() {
int Q; int K;
while (~scanf("%d%d", &Q, &K)) {
Node::K = K;
vector<Node> nodes(Q + 1);
Node *t = &nodes[Q];
t->set(0, 0);
for (int qi = 0; qi < Q; ++qi) {
int ty;
scanf("%d", &ty);
if (ty == 1) {
int D; int A;
scanf("%d%d", &D, &A);
Node *node = &nodes[qi];
node->set(D, A);
t = RBST::insertPos(t, node);
}
else if (ty == 2) {
int D;
scanf("%d", &D);
auto p = RBST::splitPos(t, D + 1);
ll ans = p.first->sumBase;
t = RBST::join(p.first, p.second);
printf("%lld\n", ans);
}
else abort();
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
D - 工場 |
User |
anta |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
4299 Byte |
Status |
WA |
Exec Time |
95 ms |
Memory |
7168 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:160:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &ty);
^
./Main.cpp:163:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &D, &A);
^
./Main.cpp:170:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &D);
^
Judge Result
Set Name |
Sample |
subtask |
All |
Score / Max Score |
0 / 0 |
0 / 600 |
0 / 400 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt, sample3.txt |
subtask |
sample2.txt, subin1.txt, subin10.txt, subin11.txt, subin12.txt, subin13.txt, subin14.txt, subin15.txt, subin16.txt, subin17.txt, subin18.txt, subin19.txt, subin2.txt, subin3.txt, subin4.txt, subin5.txt, subin6.txt, subin7.txt, subin8.txt, subin9.txt |
All |
sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt, subin1.txt, subin10.txt, subin11.txt, subin12.txt, subin13.txt, subin14.txt, subin15.txt, subin16.txt, subin17.txt, subin18.txt, subin19.txt, subin2.txt, subin3.txt, subin4.txt, subin5.txt, subin6.txt, subin7.txt, subin8.txt, subin9.txt |
Case Name |
Status |
Exec Time |
Memory |
in1.txt |
WA |
87 ms |
6912 KB |
in10.txt |
AC |
92 ms |
7168 KB |
in11.txt |
WA |
93 ms |
7168 KB |
in12.txt |
WA |
92 ms |
7168 KB |
in13.txt |
WA |
94 ms |
7168 KB |
in14.txt |
WA |
94 ms |
7168 KB |
in15.txt |
WA |
95 ms |
7168 KB |
in16.txt |
WA |
88 ms |
7168 KB |
in17.txt |
WA |
89 ms |
7168 KB |
in18.txt |
WA |
88 ms |
7168 KB |
in19.txt |
WA |
88 ms |
7168 KB |
in2.txt |
WA |
89 ms |
7040 KB |
in20.txt |
WA |
85 ms |
7168 KB |
in21.txt |
AC |
90 ms |
6912 KB |
in22.txt |
AC |
90 ms |
6912 KB |
in23.txt |
AC |
59 ms |
6912 KB |
in24.txt |
WA |
61 ms |
7040 KB |
in25.txt |
AC |
60 ms |
6912 KB |
in3.txt |
WA |
87 ms |
7040 KB |
in4.txt |
WA |
88 ms |
7040 KB |
in5.txt |
WA |
92 ms |
7040 KB |
in6.txt |
AC |
93 ms |
7168 KB |
in7.txt |
AC |
91 ms |
7168 KB |
in8.txt |
AC |
93 ms |
7168 KB |
in9.txt |
AC |
91 ms |
7168 KB |
sample1.txt |
AC |
1 ms |
256 KB |
sample2.txt |
AC |
1 ms |
256 KB |
sample3.txt |
AC |
1 ms |
256 KB |
subin1.txt |
AC |
72 ms |
6912 KB |
subin10.txt |
WA |
73 ms |
6912 KB |
subin11.txt |
WA |
71 ms |
6912 KB |
subin12.txt |
AC |
70 ms |
6912 KB |
subin13.txt |
AC |
73 ms |
6912 KB |
subin14.txt |
AC |
73 ms |
6912 KB |
subin15.txt |
AC |
72 ms |
6912 KB |
subin16.txt |
WA |
61 ms |
6912 KB |
subin17.txt |
AC |
62 ms |
6912 KB |
subin18.txt |
AC |
59 ms |
6912 KB |
subin19.txt |
AC |
59 ms |
6912 KB |
subin2.txt |
AC |
75 ms |
6912 KB |
subin3.txt |
AC |
74 ms |
6912 KB |
subin4.txt |
AC |
73 ms |
6912 KB |
subin5.txt |
AC |
70 ms |
6912 KB |
subin6.txt |
AC |
73 ms |
6912 KB |
subin7.txt |
AC |
70 ms |
6912 KB |
subin8.txt |
WA |
74 ms |
6912 KB |
subin9.txt |
WA |
69 ms |
6912 KB |