Submission #1218324
Source Code Expand
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <unordered_set>
#include <complex>
using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
// typedef complex<double> C;
int MOD;
const int _MOD = 1000000009;
const int INF = INT_MAX / 2;
double EPS = 1e-10;
template <class Monoid>
struct segtree4 {
using T = typename Monoid::T;
int N;
vector<T> a;
segtree4(const vector<T> &a0) {
for (N = 1; N < a0.size(); N<<=1);
a.resize(N<<1);
copy(a0.begin(), a0.end(), a.begin() + N);
for (int i = N - 1; i; i--)
a[i] = Monoid::op(a[i<<1], a[i<<1 | 1]);
}
segtree4(int N, const T &x = Monoid::id()) :
segtree4(vector<T>(N, x)) {}
T get(int l, int r) {
T xl = Monoid::id(), xr = Monoid::id();
for (l |= N, r |= N; l < r; l>>=1, r>>=1) {
if (l & 1) xl = Monoid::op(xl, a[l++]);
if (r & 1) xr = Monoid::op(a[--r], xr);
}
return Monoid::op(xl, xr);
}
void set(int i, const T &x) {
a[i |= N] = x;
while (i>>=1) a[i] = Monoid::op(a[i<<1], a[i<<1 | 1]);
}
};
struct unko { ll x, y; };
struct yahoo {
using T = unko;
static T id() { return unko{0, 0}; }
static T op(const T &l, const T &r) {
return unko{l.x + max(0LL, r.x - l.y), r.y + max(0LL, l.y - r.x)};
}
};
int main() {
int Q, y; cin >> Q >> y;
vector<int> q(Q), t(Q), x(Q);
rep(k, Q) {
scanf("%d%d", &q[k], &t[k]);
if (q[k] == 1) scanf("%d", &x[k]);
}
vector<i_i> p(Q);
rep(k, Q) p[k] = i_i(t[k], q[k] == 1 ? ~k : k);
sort(p.begin(), p.end());
vector<int> index(Q);
rep(i, Q) {
int k = p[i].second;
if (k < 0) k = ~k;
index[k] = i;
}
int prev = 0;
vector<unko> a(Q * 2);
rep(i, Q) {
a[i * 2] = unko{0, (ll)(p[i].first - prev) * y};
prev = p[i].first;
}
segtree4<yahoo> st(a);
rep(k, Q) {
if (q[k] == 1) st.set(index[k] * 2 + 1, unko{x[k], 0});
if (q[k] == 2) {
ll z = st.get(0, index[k] * 2 + 1).y;
printf("%lld\n", (ll)t[k] * y - z);
}
}
}
Submission Info
Submission Time |
|
Task |
D - 工場 |
User |
sugim48 |
Language |
C++14 (GCC 5.4.1) |
Score |
1000 |
Code Size |
2570 Byte |
Status |
AC |
Exec Time |
54 ms |
Memory |
14592 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:84:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &q[k], &t[k]);
^
./Main.cpp:85:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
if (q[k] == 1) scanf("%d", &x[k]);
^
Judge Result
Set Name |
Sample |
subtask |
All |
Score / Max Score |
0 / 0 |
600 / 600 |
400 / 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 |
AC |
50 ms |
14336 KB |
in10.txt |
AC |
53 ms |
14592 KB |
in11.txt |
AC |
52 ms |
14592 KB |
in12.txt |
AC |
52 ms |
14592 KB |
in13.txt |
AC |
53 ms |
14464 KB |
in14.txt |
AC |
52 ms |
14592 KB |
in15.txt |
AC |
52 ms |
14464 KB |
in16.txt |
AC |
54 ms |
14464 KB |
in17.txt |
AC |
50 ms |
14592 KB |
in18.txt |
AC |
51 ms |
14592 KB |
in19.txt |
AC |
51 ms |
14592 KB |
in2.txt |
AC |
49 ms |
14336 KB |
in20.txt |
AC |
51 ms |
14592 KB |
in21.txt |
AC |
50 ms |
14336 KB |
in22.txt |
AC |
50 ms |
14336 KB |
in23.txt |
AC |
48 ms |
14336 KB |
in24.txt |
AC |
48 ms |
14336 KB |
in25.txt |
AC |
48 ms |
14336 KB |
in3.txt |
AC |
49 ms |
14336 KB |
in4.txt |
AC |
49 ms |
14336 KB |
in5.txt |
AC |
50 ms |
14336 KB |
in6.txt |
AC |
52 ms |
14592 KB |
in7.txt |
AC |
53 ms |
14592 KB |
in8.txt |
AC |
52 ms |
14592 KB |
in9.txt |
AC |
53 ms |
14592 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 |
50 ms |
14336 KB |
subin10.txt |
AC |
50 ms |
14336 KB |
subin11.txt |
AC |
51 ms |
14336 KB |
subin12.txt |
AC |
51 ms |
14336 KB |
subin13.txt |
AC |
51 ms |
14336 KB |
subin14.txt |
AC |
51 ms |
14464 KB |
subin15.txt |
AC |
51 ms |
14336 KB |
subin16.txt |
AC |
48 ms |
14336 KB |
subin17.txt |
AC |
48 ms |
14336 KB |
subin18.txt |
AC |
48 ms |
14336 KB |
subin19.txt |
AC |
49 ms |
14336 KB |
subin2.txt |
AC |
51 ms |
14336 KB |
subin3.txt |
AC |
51 ms |
14336 KB |
subin4.txt |
AC |
51 ms |
14336 KB |
subin5.txt |
AC |
51 ms |
14336 KB |
subin6.txt |
AC |
51 ms |
14336 KB |
subin7.txt |
AC |
51 ms |
14336 KB |
subin8.txt |
AC |
51 ms |
14336 KB |
subin9.txt |
AC |
51 ms |
14336 KB |