Submission #270395

# Submission time Handle Problem Language Result Execution time Memory
270395 2020-08-17T14:45:30 Z Haunted_Cpp Labels (NOI20_labels) C++17
100 / 100
115 ms 35064 KB
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

class SegmentTree {
private: 
  struct Node {
    long long mn, mx;
    long long lazy;
    Node () {
      mn = 1e18;
      mx = -1e18;
      lazy = 0;
    }
    void merge(Node l, Node r) {
      mn = min(l.mn, r.mn);
      mx = max(l.mx, r.mx);
    }
  };
  const int LO, HI;
  vector<Node> seg;
  void build(int l, int r, int node, const vector<long long> &arr) {
    if (l == r) {
      seg[node].mn = seg[node].mx = arr[l];
    } else {
      const int mid = l + (r - l) / 2;
      build(l, mid, 2 * node + 1, arr);
      build(mid + 1, r, 2 * node + 2, arr);
      seg[node].merge(seg[2 * node + 1], seg[2 * node + 2]);
    }
  }
  void push(int l, int r, int node) {
    if (seg[node].lazy == 0) return;
    seg[node].mx += seg[node].lazy;
    seg[node].mn += seg[node].lazy;
    if (l != r) {
      seg[2 * node + 1].lazy += seg[node].lazy;
      seg[2 * node + 2].lazy += seg[node].lazy;
    }
    seg[node].lazy = 0;
  }
  void range_update(int ql, int qr, int delta, int l, int r, int node) {
    push(l, r, node);
    if (l > qr || r < ql) return;
    if (l >= ql && r <= qr) {
      seg[node].lazy = delta;
      push(l, r, node);
      return;
    }
    const int mid = l + (r - l) / 2;
    range_update(ql, qr, delta, l, mid, 2 * node + 1);
    range_update(ql, qr, delta, mid + 1, r, 2 * node + 2);
    seg[node].merge(seg[2 * node + 1], seg[2 * node + 2]);
  }
  void dfs(int l, int r, int node) {
    push(l, r, node);
    if (l == r) {
      cout << seg[node].mx << ' ';
      return;
    }
    const int mid = l + (r - l) / 2;
    dfs(l, mid, 2 * node + 1);
    dfs(mid + 1, r, 2 * node + 2);
  }
public:
  SegmentTree(const vector<long long> &arr) : LO(0), HI((int) arr.size() - 1) {
    seg.clear();
    seg.resize(4 * (int)arr.size());
    build(LO, HI, 0, arr);
  };
  void range_update(int ql, int qr, int delta) {
    range_update(ql, qr, delta, LO, HI, 0);
  }
  void get_ans() {
    dfs(LO, HI, 0);
  }
  long long get_max() {
    return seg[0].mx;
  }
  long long get_min() {
    return seg[0].mn;
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  int n;
  cin >> n;
  vector<long long> arr(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> arr[i];
    if (i) arr[i] += arr[i - 1];
  }
  SegmentTree seg(arr);
  int work = 0;
  for (int i = 1; i <= n; i++) {
    seg.range_update(0, n - 2, +i);
    const long long mn = seg.get_min();
    const long long mx = seg.get_max();
    if (mn >= 1 && mx <= n) ++work;
    seg.range_update(0, n - 2, -i);
  }
  if (work != 1) {
    cout << "-1" << '\n';
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    seg.range_update(0, n - 2, +i);
    const long long mn = seg.get_min();
    const long long mx = seg.get_max();
    if (mn >= 1 && mx <= n) {
      cout << i << ' ';
      seg.get_ans();
      cout << '\n';
      return 0;
    }
    seg.range_update(0, n - 2, -i);
  }
  return 0;
}
 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 1 ms 288 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 0 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 1 ms 288 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 0 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 488 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 1 ms 416 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 416 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 1 ms 384 KB Output is correct
81 Correct 1 ms 384 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 1 ms 384 KB Output is correct
86 Correct 1 ms 384 KB Output is correct
87 Correct 1 ms 384 KB Output is correct
88 Correct 1 ms 384 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 1 ms 384 KB Output is correct
93 Correct 1 ms 384 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 0 ms 384 KB Output is correct
98 Correct 1 ms 512 KB Output is correct
99 Correct 0 ms 384 KB Output is correct
100 Correct 1 ms 384 KB Output is correct
101 Correct 1 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 33528 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 80 ms 33784 KB Output is correct
4 Correct 43 ms 31480 KB Output is correct
5 Correct 46 ms 31744 KB Output is correct
6 Correct 45 ms 31608 KB Output is correct
7 Correct 43 ms 31480 KB Output is correct
8 Correct 46 ms 31608 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 0 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 1 ms 288 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 0 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 0 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 0 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 0 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 0 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 0 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 488 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 1 ms 384 KB Output is correct
67 Correct 1 ms 384 KB Output is correct
68 Correct 1 ms 416 KB Output is correct
69 Correct 1 ms 384 KB Output is correct
70 Correct 1 ms 416 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 1 ms 384 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 1 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 1 ms 384 KB Output is correct
81 Correct 1 ms 384 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 1 ms 384 KB Output is correct
86 Correct 1 ms 384 KB Output is correct
87 Correct 1 ms 384 KB Output is correct
88 Correct 1 ms 384 KB Output is correct
89 Correct 1 ms 384 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 1 ms 384 KB Output is correct
93 Correct 1 ms 384 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 0 ms 384 KB Output is correct
98 Correct 1 ms 512 KB Output is correct
99 Correct 0 ms 384 KB Output is correct
100 Correct 1 ms 384 KB Output is correct
101 Correct 1 ms 384 KB Output is correct
102 Correct 1 ms 384 KB Output is correct
103 Correct 1 ms 384 KB Output is correct
104 Correct 74 ms 33528 KB Output is correct
105 Correct 1 ms 384 KB Output is correct
106 Correct 80 ms 33784 KB Output is correct
107 Correct 43 ms 31480 KB Output is correct
108 Correct 46 ms 31744 KB Output is correct
109 Correct 45 ms 31608 KB Output is correct
110 Correct 43 ms 31480 KB Output is correct
111 Correct 46 ms 31608 KB Output is correct
112 Correct 0 ms 384 KB Output is correct
113 Correct 1 ms 384 KB Output is correct
114 Correct 59 ms 32760 KB Output is correct
115 Correct 100 ms 34920 KB Output is correct
116 Correct 57 ms 32888 KB Output is correct
117 Correct 60 ms 32812 KB Output is correct
118 Correct 91 ms 34936 KB Output is correct
119 Correct 55 ms 32760 KB Output is correct
120 Correct 102 ms 34936 KB Output is correct
121 Correct 92 ms 34936 KB Output is correct
122 Correct 91 ms 34936 KB Output is correct
123 Correct 60 ms 32888 KB Output is correct
124 Correct 96 ms 34936 KB Output is correct
125 Correct 89 ms 34936 KB Output is correct
126 Correct 95 ms 35056 KB Output is correct
127 Correct 91 ms 34936 KB Output is correct
128 Correct 56 ms 32760 KB Output is correct
129 Correct 89 ms 34936 KB Output is correct
130 Correct 92 ms 34936 KB Output is correct
131 Correct 90 ms 34936 KB Output is correct
132 Correct 115 ms 34936 KB Output is correct
133 Correct 96 ms 34936 KB Output is correct
134 Correct 56 ms 32760 KB Output is correct
135 Correct 92 ms 34940 KB Output is correct
136 Correct 56 ms 32888 KB Output is correct
137 Correct 59 ms 32760 KB Output is correct
138 Correct 55 ms 32880 KB Output is correct
139 Correct 56 ms 32888 KB Output is correct
140 Correct 55 ms 32836 KB Output is correct
141 Correct 55 ms 32888 KB Output is correct
142 Correct 96 ms 34936 KB Output is correct
143 Correct 57 ms 32888 KB Output is correct
144 Correct 55 ms 32888 KB Output is correct
145 Correct 90 ms 34936 KB Output is correct
146 Correct 89 ms 34936 KB Output is correct
147 Correct 93 ms 35064 KB Output is correct
148 Correct 90 ms 34936 KB Output is correct
149 Correct 73 ms 33400 KB Output is correct
150 Correct 79 ms 33784 KB Output is correct
151 Correct 42 ms 31480 KB Output is correct
152 Correct 47 ms 31608 KB Output is correct
153 Correct 44 ms 31608 KB Output is correct
154 Correct 42 ms 31488 KB Output is correct
155 Correct 46 ms 31608 KB Output is correct
156 Correct 0 ms 384 KB Output is correct
157 Correct 0 ms 384 KB Output is correct
158 Correct 56 ms 32892 KB Output is correct
159 Correct 0 ms 384 KB Output is correct
160 Correct 90 ms 34856 KB Output is correct
161 Correct 56 ms 32888 KB Output is correct
162 Correct 56 ms 32888 KB Output is correct
163 Correct 56 ms 32888 KB Output is correct