이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
map<int, int> cnt;
int tot = 0, pref[500010];
void ins (int a) {
if (cnt[a]) cnt[a]++;
else {
cnt[a] = 1; tot++;
}
};
void er (int a) {
cnt[a]--;
if (cnt[a] == 0) tot--;
};
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int N, M; cin >> N >> M;
vector<int> points;
vector<pair<int, int>> events;
for (int i = 1; i <= M; i++) {
int k; cin >> k;
for (int j = 0; j < k; j++) {
int x; cin >> x;
pref[j+1] = pref[j] + x;
}
for (int j = 0; j <= k; j++) {
points.push_back(pref[j] + 1); points.push_back(N - pref[k] + pref[j] + 1);
events.push_back({pref[j] + 1, i}); events.push_back({N - pref[k] + pref[j] + 1, -i});
}
}
sort(points.begin(), points.end());
sort(events.begin(), events.end());
points.erase(unique(points.begin(), points.end()), points.end());
int ans = N, ind = 0, esz = events.size(), psz = points.size();
for (int i = 0; i < psz; i++) {
int point = points[i];
while (ind < esz && events[ind].first == point) {
if (events[ind].second > 0) ins(events[ind].second);
else er(abs(events[ind].second));
ind++;
}
if (tot == M) {
if (i+1 < psz) ans -= points[i+1] - point;
else ans -= N - point;
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |