Submission #2601273
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);
template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
each(x,vec) is >> x;
return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
rep(i,vec.size()) {
if (i) os << " ";
os << vec[i];
}
return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
rep(i,vec.size()) {
if (i) os << endl;
os << vec[i];
}
return os;
}
class SegmentManager {
const ll D;
map<ll, ll> cnt;
ll ans;
ll f(ll l, ll r) {
// assert(l < r);
if (r - l - 1 <= D) {
return r - l - 1;
}
return 0;
}
void s_insert(ll day) {
// cout << "s_insert: " << day << endl;
// assert(s.count(day) == 0);
auto it = cnt.upper_bound(day);
ll l = -linf, r = linf;
// right
if (it != cnt.end()) {
r = it->first;
ans += f(day, r);
}
// left
if (it != cnt.begin()) {
--it;
l = it->first;
ans += f(l, day);
}
ans -= f(l, r);
// self
++ans;
}
void s_remove(ll day) {
// cout << "s_remove: " << day << endl;
// assert(s.count(day) > 0);
auto it = cnt.upper_bound(day);
ll l = -linf, r = linf;
// right
if (it != cnt.end()) {
r = it->first;
ans -= f(day, r);
}
// left
if (it != cnt.begin()) {
--it;
l = it->first;
ans -= f(l, day);
}
ans += f(l, r);
// self
--ans;
}
public:
SegmentManager(const ll D) : D(D), ans(0) {}
void insert(ll day) {
if (cnt.count(day) == 0) {
s_insert(day);
}
++cnt[day];
}
void remove(ll day) {
// assert(cnt[day] > 0);
if (--cnt[day] == 0) {
cnt.erase(day);
s_remove(day);
}
}
ll find() {
return ans;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll Y, W, n, m, D; cin >> Y >> W >> n >> m >> D;
vector<ll> A(n); cin >> A;
vector<vector<ll>> C2Bs(W);
rep(i, n) --A[i];
rep(i, m) {
ll B, C; cin >> B >> C; --B, --C;
C2Bs[C].pb(B);
}
SegmentManager sm(D);
rep(C, W) each(B, C2Bs[C]) {
sm.insert(B * W + C);
}
rep(d, W) {
rep(i, n) {
sm.insert(A[i] + d);
}
cout << sm.find() << endl;
if (d+1 < W) {
rep(i, n) {
sm.remove(A[i] + d);
}
ll C = d;
each(B, C2Bs[C]) {
sm.remove(B * W + C);
sm.insert(B * W + C + W);
}
}
}
}
Submission Info
Submission Time |
|
Task |
E - 祝日 |
User |
drafear |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
3683 Byte |
Status |
AC |
Exec Time |
3784 ms |
Memory |
14592 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
All |
Score / Max Score |
0 / 0 |
600 / 600 |
100 / 100 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Subtask1 |
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, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, sample-01.txt, sample-02.txt |
All |
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, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.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, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 02-21.txt, 02-22.txt, 02-23.txt, 02-24.txt, 02-25.txt, 02-26.txt, 02-27.txt, 02-28.txt, 02-29.txt, 02-30.txt, 02-31.txt, 02-32.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
349 ms |
12416 KB |
01-02.txt |
AC |
275 ms |
10624 KB |
01-03.txt |
AC |
245 ms |
8320 KB |
01-04.txt |
AC |
57 ms |
3072 KB |
01-05.txt |
AC |
189 ms |
8064 KB |
01-06.txt |
AC |
172 ms |
7552 KB |
01-07.txt |
AC |
111 ms |
7240 KB |
01-08.txt |
AC |
72 ms |
3200 KB |
01-09.txt |
AC |
274 ms |
10240 KB |
01-10.txt |
AC |
46 ms |
2432 KB |
01-11.txt |
AC |
243 ms |
10624 KB |
01-12.txt |
AC |
179 ms |
9600 KB |
01-13.txt |
AC |
264 ms |
11136 KB |
01-14.txt |
AC |
82 ms |
4480 KB |
01-15.txt |
AC |
211 ms |
8704 KB |
01-16.txt |
AC |
56 ms |
1152 KB |
01-17.txt |
AC |
30 ms |
2432 KB |
01-18.txt |
AC |
187 ms |
7552 KB |
01-19.txt |
AC |
340 ms |
12416 KB |
01-20.txt |
AC |
298 ms |
11008 KB |
02-01.txt |
AC |
2187 ms |
13824 KB |
02-02.txt |
AC |
718 ms |
8832 KB |
02-03.txt |
AC |
781 ms |
11264 KB |
02-04.txt |
AC |
1237 ms |
11648 KB |
02-05.txt |
AC |
2360 ms |
12288 KB |
02-06.txt |
AC |
1294 ms |
9472 KB |
02-07.txt |
AC |
114 ms |
7260 KB |
02-08.txt |
AC |
220 ms |
1664 KB |
02-09.txt |
AC |
1545 ms |
11136 KB |
02-10.txt |
AC |
159 ms |
2176 KB |
02-11.txt |
AC |
1926 ms |
11648 KB |
02-12.txt |
AC |
435 ms |
8960 KB |
02-13.txt |
AC |
622 ms |
8704 KB |
02-14.txt |
AC |
111 ms |
1664 KB |
02-15.txt |
AC |
551 ms |
8448 KB |
02-16.txt |
AC |
29 ms |
384 KB |
02-17.txt |
AC |
47 ms |
2432 KB |
02-18.txt |
AC |
238 ms |
7552 KB |
02-19.txt |
AC |
2507 ms |
12416 KB |
02-20.txt |
AC |
67 ms |
7284 KB |
02-21.txt |
AC |
457 ms |
2304 KB |
02-22.txt |
AC |
2 ms |
256 KB |
02-23.txt |
AC |
3784 ms |
14592 KB |
02-24.txt |
AC |
1785 ms |
9600 KB |
02-25.txt |
AC |
1072 ms |
8960 KB |
02-26.txt |
AC |
2 ms |
256 KB |
02-27.txt |
AC |
112 ms |
640 KB |
02-28.txt |
AC |
426 ms |
1664 KB |
02-29.txt |
AC |
139 ms |
7296 KB |
02-30.txt |
AC |
148 ms |
7424 KB |
02-31.txt |
AC |
149 ms |
7424 KB |
02-32.txt |
AC |
270 ms |
1280 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |
sample-03.txt |
AC |
1 ms |
256 KB |
sample-04.txt |
AC |
1 ms |
256 KB |