This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;
#ifdef LOCAL
#define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
int l, r;
vector<pii> segs;
vector<pii> mySegs;
void addSeg(int segL, int segR) {
if(segL > segR)
return;
mySegs.emplace_back(segL, segR);
}
int main()
{
startTime = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d%d", &l, &r);
for (int i = 0; i < r; i++) {
int x;
scanf("%d", &x);
vector<int> a(x);
for (int j = 0; j < x; j++)
scanf("%d", &a[j]);
int sL = 0;
int sR = accumulate(a.begin(), a.end(), 0);
mySegs.clear();
addSeg(1, l - sR);
for (int j = 0; j < x; j++) {
sL += a[j];
sR -= a[j];
addSeg(sL + 1, l - sR);
}
vector<pii> events;
for (int j = 0; j < mySegs.size(); j++) {
events.emplace_back(mySegs[j].first, -1);
events.emplace_back(mySegs[j].second, 1);
}
int bal = 0, stS = -1;
sort(events.begin(), events.end());
for (int j = 0; j < events.size(); j++) {
if(events[j].second == -1) {
if(bal == 0)
stS = events[j].first;
bal++;
} else {
bal--;
if(bal == 0) {
segs.emplace_back(stS, events[j].first);
}
}
}
}
vector<pii> events;
for (int i = 0; i < segs.size(); i++) {
events.emplace_back(segs[i].first, -1);
events.emplace_back(segs[i].second, 1);
}
sort(events.begin(), events.end());
int bal = 0, ans = 0, stS = 0;
for (int i = 0; i < events.size(); i++) {
if(events[i].second == -1) {
bal++;
if(bal == r)
stS = events[i].first;
} else {
if(bal == r)
ans += events[i].first - stS + 1;
bal--;
}
}
printf("%d\n", l - ans);
}
Compilation message (stderr)
lasers.cpp: In function 'int main()':
lasers.cpp:86:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int j = 0; j < mySegs.size(); j++) {
| ~~^~~~~~~~~~~~~~~
lasers.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (int j = 0; j < events.size(); j++) {
| ~~^~~~~~~~~~~~~~~
lasers.cpp:106:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for (int i = 0; i < segs.size(); i++) {
| ~~^~~~~~~~~~~~~
lasers.cpp:112:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for (int i = 0; i < events.size(); i++) {
| ~~^~~~~~~~~~~~~~~
lasers.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | scanf("%d%d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~
lasers.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
lasers.cpp:75:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | scanf("%d", &a[j]);
| ~~~~~^~~~~~~~~~~~~
# | 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... |