-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathF.cpp
More file actions
168 lines (146 loc) · 4.09 KB
/
F.cpp
File metadata and controls
168 lines (146 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <bits/stdc++.h>
#define int long long
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int) (x).size())
using namespace std;
double safe_sqrt(double x) {
return sqrt(max((double)0.0,x));
}
int GI(ll& x) {
return scanf("%lld", &x);
}
const int INF = 1000111000111000111LL;
const int MN = 300111;
struct Line {
int a, b;
int from, to;
} lines[MN];
struct Hull {
vector<double> x;
vector<int> a;
vector<int> b;
void init() {
x.clear();
a.clear();
b.clear();
}
void insert(Line l) {
if (a.empty()) {
x.push_back(-INF);
a.push_back(l.a);
b.push_back(l.b);
}
else {
double xNew = -INF;
while (!a.empty()) {
if (a.back() == l.a) {
b.back() = max(b.back(), l.b);
return;
}
xNew = 1.0 * (b.back() - l.b) / (l.a - a.back());
if (xNew < x.back()) {
a.pop_back();
b.pop_back();
x.pop_back();
}
else break;
}
a.push_back(l.a);
b.push_back(l.b);
x.push_back(xNew);
}
}
int get(int x0) {
if (a.empty()) {
return -INF;
}
int i = upper_bound(x.begin(), x.end(), x0) - x.begin() - 1;
return a[i] * x0 + b[i];
}
};
Hull it[MN * 4];
void init(int i, int l, int r) {
it[i].init();
if (l == r) return ;
int mid = (l + r) >> 1;
init(i<<1, l, mid);
init(i<<1|1, mid+1, r);
}
void update(int i, int l, int r, int u, int v, Line t) {
if (v < l || r < u) return ;
if (u <= l && r <= v) {
it[i].insert(t);
return ;
}
int mid = (l + r) >> 1;
update(i<<1, l, mid, u, v, t);
update(i<<1|1, mid+1, r, u, v, t);
}
int get(int i, int l, int r, int time, int x0) {
if (time < l || r < time) return -INF;
int res = it[i].get(x0);
if (l == r) return res;
int mid = (l + r) >> 1;
res = max(res, get(i<<1, l, mid, time, x0));
res = max(res, get(i<<1|1, mid+1, r, time, x0));
return res;
}
bool operator < (const Line& u, const Line& v) {
if (u.a != v.a) return u.a < v.a;
return u.b > v.b;
}
int nLine, id[MN];
struct Query {
int time, x0;
} queries[MN];
int nQuery;
#undef int
int main() {
#define int long long
ios :: sync_with_stdio(0); cin.tie(0);
cout << (fixed) << setprecision(9);
int q;
while (GI(q) == 1) {
nLine = 0;
nQuery = 0;
FOR(i,1,q) {
int typ; GI(typ);
if (typ == 1) {
++nLine;
lines[nLine].from = i;
lines[nLine].to = q;
GI(lines[nLine].a);
GI(lines[nLine].b);
id[i] = nLine;
}
else if (typ == 2) {
int x; GI(x);
int lineId = id[x];
lines[lineId].to = i;
}
else {
++nQuery;
queries[nQuery].time = i;
GI(queries[nQuery].x0);
}
}
sort(lines+1, lines+nLine+1);
init(1,1,q);
FOR(i,1,nLine) {
update(1, 1, q, lines[i].from, lines[i].to, lines[i]);
}
FOR(i,1,nQuery) {
auto t = get(1, 1, q, queries[i].time, queries[i].x0);
if (t == -INF) puts("EMPTY SET");
else printf("%lld\n", t);
}
}
}