Submission #647459

# Submission time Handle Problem Language Result Execution time Memory
647459 2022-10-02T15:56:52 Z LeonaRaging Lasers (NOI19_lasers) C++14
100 / 100
954 ms 89980 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define ll long long
#define pb push_back
#define db(val) "[" #val " = " << (val) << "] "

const ll mod = 1e9 + 7;
const int maxn = 1e6 + 4;
const int INF = 1e9;

int m, n, tot, pre[maxn], cnt[maxn];
vector<int> vals, sum[maxn];
vector<pair<int,int>> queries;

void insert(int x) {
    if (cnt[x] == 0) tot++;
    cnt[x]++;
}

void erase(int x) {
    cnt[x]--;
    if (cnt[x] == 0) tot--;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    cin >> m >> n;
    for (int i = 1; i <= n; i++) {
        int num; cin >> num;
        for (int i = 1; i <= num; i++) {
            int x; cin >> x;
            pre[i] = pre[i - 1] + x;
        }
        for (int j = 0; j <= num; j++) {
            vals.pb(pre[j] + 1); vals.pb(m - (pre[num] - pre[j]) + 1);
            queries.pb({pre[j] + 1, i}); queries.pb({m - (pre[num] - pre[j]) + 1, -i});
        }
    }
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (auto &it : queries) {
        it.fi = lower_bound(vals.begin(), vals.end(), it.fi) - vals.begin() + 1;
        sum[it.fi].pb(it.se);
    }
    int res = m;
    for (int i = 1; i < int(vals.size()); i++) {
        for (auto x : sum[i])
            if (x < 0) erase(-x);
            else insert(x);
        if (tot == n)
            res -= vals[i] - vals[i - 1];
    }   
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23812 KB Output is correct
2 Correct 12 ms 23776 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 12 ms 23816 KB Output is correct
6 Correct 13 ms 23800 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 15 ms 23764 KB Output is correct
9 Correct 14 ms 23764 KB Output is correct
10 Correct 13 ms 23816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23812 KB Output is correct
2 Correct 12 ms 23776 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 12 ms 23816 KB Output is correct
6 Correct 13 ms 23800 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 15 ms 23764 KB Output is correct
9 Correct 14 ms 23764 KB Output is correct
10 Correct 13 ms 23816 KB Output is correct
11 Correct 13 ms 23952 KB Output is correct
12 Correct 173 ms 67656 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 14 ms 23700 KB Output is correct
15 Correct 13 ms 23952 KB Output is correct
16 Correct 13 ms 23892 KB Output is correct
17 Correct 905 ms 89980 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 13 ms 23792 KB Output is correct
20 Correct 13 ms 23816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 46772 KB Output is correct
2 Correct 37 ms 29692 KB Output is correct
3 Correct 48 ms 31540 KB Output is correct
4 Correct 133 ms 47112 KB Output is correct
5 Correct 77 ms 36192 KB Output is correct
6 Correct 169 ms 53748 KB Output is correct
7 Correct 15 ms 24216 KB Output is correct
8 Correct 194 ms 55856 KB Output is correct
9 Correct 72 ms 37092 KB Output is correct
10 Correct 150 ms 49228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23816 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 14 ms 23764 KB Output is correct
7 Correct 13 ms 23892 KB Output is correct
8 Correct 13 ms 23892 KB Output is correct
9 Correct 14 ms 23804 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 46772 KB Output is correct
2 Correct 37 ms 29692 KB Output is correct
3 Correct 48 ms 31540 KB Output is correct
4 Correct 133 ms 47112 KB Output is correct
5 Correct 77 ms 36192 KB Output is correct
6 Correct 169 ms 53748 KB Output is correct
7 Correct 15 ms 24216 KB Output is correct
8 Correct 194 ms 55856 KB Output is correct
9 Correct 72 ms 37092 KB Output is correct
10 Correct 150 ms 49228 KB Output is correct
11 Correct 12 ms 23816 KB Output is correct
12 Correct 12 ms 23764 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 13 ms 23764 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 14 ms 23764 KB Output is correct
17 Correct 13 ms 23892 KB Output is correct
18 Correct 13 ms 23892 KB Output is correct
19 Correct 14 ms 23804 KB Output is correct
20 Correct 13 ms 23764 KB Output is correct
21 Correct 732 ms 75876 KB Output is correct
22 Correct 115 ms 34220 KB Output is correct
23 Correct 55 ms 31804 KB Output is correct
24 Correct 231 ms 54176 KB Output is correct
25 Correct 713 ms 75724 KB Output is correct
26 Correct 220 ms 43860 KB Output is correct
27 Correct 85 ms 32768 KB Output is correct
28 Correct 731 ms 75660 KB Output is correct
29 Correct 740 ms 76148 KB Output is correct
30 Correct 182 ms 48320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23812 KB Output is correct
2 Correct 12 ms 23776 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23824 KB Output is correct
5 Correct 12 ms 23816 KB Output is correct
6 Correct 13 ms 23800 KB Output is correct
7 Correct 13 ms 23812 KB Output is correct
8 Correct 15 ms 23764 KB Output is correct
9 Correct 14 ms 23764 KB Output is correct
10 Correct 13 ms 23816 KB Output is correct
11 Correct 13 ms 23952 KB Output is correct
12 Correct 173 ms 67656 KB Output is correct
13 Correct 13 ms 23764 KB Output is correct
14 Correct 14 ms 23700 KB Output is correct
15 Correct 13 ms 23952 KB Output is correct
16 Correct 13 ms 23892 KB Output is correct
17 Correct 905 ms 89980 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 13 ms 23792 KB Output is correct
20 Correct 13 ms 23816 KB Output is correct
21 Correct 135 ms 46772 KB Output is correct
22 Correct 37 ms 29692 KB Output is correct
23 Correct 48 ms 31540 KB Output is correct
24 Correct 133 ms 47112 KB Output is correct
25 Correct 77 ms 36192 KB Output is correct
26 Correct 169 ms 53748 KB Output is correct
27 Correct 15 ms 24216 KB Output is correct
28 Correct 194 ms 55856 KB Output is correct
29 Correct 72 ms 37092 KB Output is correct
30 Correct 150 ms 49228 KB Output is correct
31 Correct 12 ms 23816 KB Output is correct
32 Correct 12 ms 23764 KB Output is correct
33 Correct 12 ms 23764 KB Output is correct
34 Correct 13 ms 23764 KB Output is correct
35 Correct 12 ms 23764 KB Output is correct
36 Correct 14 ms 23764 KB Output is correct
37 Correct 13 ms 23892 KB Output is correct
38 Correct 13 ms 23892 KB Output is correct
39 Correct 14 ms 23804 KB Output is correct
40 Correct 13 ms 23764 KB Output is correct
41 Correct 732 ms 75876 KB Output is correct
42 Correct 115 ms 34220 KB Output is correct
43 Correct 55 ms 31804 KB Output is correct
44 Correct 231 ms 54176 KB Output is correct
45 Correct 713 ms 75724 KB Output is correct
46 Correct 220 ms 43860 KB Output is correct
47 Correct 85 ms 32768 KB Output is correct
48 Correct 731 ms 75660 KB Output is correct
49 Correct 740 ms 76148 KB Output is correct
50 Correct 182 ms 48320 KB Output is correct
51 Correct 68 ms 34816 KB Output is correct
52 Correct 920 ms 89200 KB Output is correct
53 Correct 954 ms 89160 KB Output is correct
54 Correct 177 ms 41248 KB Output is correct
55 Correct 396 ms 66136 KB Output is correct
56 Correct 172 ms 53384 KB Output is correct
57 Correct 281 ms 51264 KB Output is correct
58 Correct 936 ms 89868 KB Output is correct
59 Correct 169 ms 43924 KB Output is correct
60 Correct 243 ms 52644 KB Output is correct