답안 #372647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372647 2021-03-01T08:29:44 Z hohohaha 코알라 (JOI13_koala) C++14
0 / 100
195 ms 15464 KB
#include<bits/stdc++.h>

using namespace std;

#define loop(i, l, r) for(int i = (int) l; i <= (int) r; i++)
#define rloop(i, r, l) for(int i = (int) r; i >= (int) l; i--)

#define vi vector<int>
#define eb emplace_back
#define ii pair<int, int>
#define fi first
#define se second
#define all(x) begin(x), end(x)

#define rand
#define endl '\n'
#define sp ' '

#define int long long

const int maxN = 2e5, inf = LLONG_MAX / 100ll;

int N; 
int T[maxN], B[maxN], A, K, M, D;
struct 
{
	#define m (l + r) / 2
	#define lc 2 * i, l, m
	#define rc 2 * i + 1, m + 1, r 
	vi mx = vi(4 * maxN, -inf), lz = vi(4 * maxN, 0);
	void pd(int i, int l, int r)
	{
		if(lz[i])
		{
			mx[i] += lz[i];
			if(l < r) lz[2 * i] += lz[i], lz[2 * i + 1] += lz[i];
			lz[i] = 0;
		}
	}
	void add(int i, int l, int r, int ql, int qr, int v)
	{
//		cout << 1 << endl;
		pd(i, l, r);
		if(l > qr or ql > r) return;
		if(ql <= l and r <= qr) 
		{
			lz[i] += v;
			pd(i, l, r);
		}
		else
		{
			add(lc, ql, qr, v);
			add(rc, ql, qr, v);
			mx[i] = max(mx[2 * i], mx[2 * i + 1]);
		}
	}
	int get(int Size)
	{
		pd(1, 1, Size);
		return mx[1];
	}
	void assign(int i, int l, int r, int p, int v)
	{
//		cout << i << sp << l << sp << r << endl;
		pd(i, l, r);
		if(l > p or p > r) return;
		if(l == r) mx[i] = max(mx[i], v);
		else
		{
			assign(lc, p, v);
			assign(rc, p, v);
			mx[i] = max(mx[2 * i], mx[2 * i + 1]);
		}
	}
} IT;

vi Ax;
int gcpr(int x)
{
	return lower_bound(all(Ax), x) - begin(Ax) + 1;
}
int NP;
void add(int d)
{
	int T = d / D;
	d %= D;
	IT.add(1, 1, Ax.size(), 1, Ax.size(), - T * A);
	int i = gcpr(NP), tmp = (NP + d) % D;
	int n = gcpr(tmp);
//	cout << "-> " << i << sp << N << endl;
	if(n == i) return;
	if(n > i)
	{
		IT.add(1, 1, Ax.size(), i, n - 1, -A);
	}
	else
	{
		IT.add(1, 1, Ax.size(), i, Ax.size(), -A);
		if(n > 1) IT.add(1, 1, Ax.size(), 1, n - 1, -A);
	}
	NP = tmp;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> K >> M >> D >> A >> N;
	T[0] = K;
	loop(i,1, N)
	{
		cin >> T[i] >> B[i];
		Ax.eb(T[i] % D);
	}
	T[N + 1] = M;
	Ax.eb(K % D);
	Ax.eb(M % D);
	sort(all(Ax));
	loop(i, 0, N + 1)
	{
		if(!i) 
		{
			add(T[i]);
//			cout << "done";
			IT.assign(1, 1, Ax.size(), gcpr(M % D), 0);
//			cout << "done";
		}
		else
		{
			add(T[i] - T[i - 1]);
			int v = IT.get(Ax.size()) + B[i];
			if(i == N + 1) return cout << v, 0;
			IT.assign(1, 1, Ax.size(), gcpr(NP % D), v);
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12908 KB Output is correct
2 Correct 9 ms 12908 KB Output is correct
3 Incorrect 9 ms 12908 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 191 ms 15464 KB Output is correct
2 Correct 149 ms 15336 KB Output is correct
3 Correct 52 ms 14572 KB Output is correct
4 Incorrect 156 ms 15336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 15336 KB Output is correct
2 Correct 169 ms 15336 KB Output is correct
3 Correct 146 ms 15336 KB Output is correct
4 Correct 116 ms 15336 KB Output is correct
5 Incorrect 102 ms 14444 KB Output isn't correct
6 Halted 0 ms 0 KB -