Submission #763414

#TimeUsernameProblemLanguageResultExecution timeMemory
763414caganyanmazAdvertisement 2 (JOI23_ho_t2)C++17
100 / 100
1587 ms117624 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; struct SegTree { int ll, rr; vector<int> left, right; vector<bool> data; SegTree(int ll, int rr) : ll(ll), rr(rr), data(1, false), left(1, -1), right(1, -1) {} void cc(int index) { if (left[index] == -1) { left[index] = data.size(); data.pb(false); left.pb(-1); right.pb(-1); right[index] = data.size(); data.pb(false); left.pb(-1); right.pb(-1); } } void set(int l, int r, int index, int i, int val) { if (i >= r || l > i) return; if (l + 1 == r) { data[index] = val; return; } cc(index); int m = l+r>>1; set(l, m, left[index], i, val); set(m, r, right[index], i, val); data[index] = data[left[index]] || data[right[index]]; } bool get(int l, int r, int index, int ss, int ee) { if (ss >= r || l >= ee || index == -1) return false; if (ee >= r && l >= ss) return data[index]; int m = l+r>>1; bool lres = get(l, m, left[index], ss, ee); bool rres = get(m, r, right[index], ss, ee); return lres || rres; } void set(int i, int val) { set(ll, rr, 0, i, val); } bool get(int ss, int ee) { return get(ll, rr, 0, ss, ee); } void reset() { for (int i = 0; i < data.size(); i++) data[i] = false; } }; constexpr int BOUND = 2e9; int main() { int n; cin >> n; vector<array<int, 3>> v(n); vector<bool> necessary(n, true); for (int i = 0; i < n; i++) { auto& [x, e, j] = v[i]; cin >> x >> e; j = i; } SegTree st(0, BOUND); sort(v.begin(), v.end(), [] (array<int, 3> a1, array<int, 3> a2) -> bool { int v1 = a1[1] + a1[0]; int v2 = a2[1] + a2[0]; if (v1 == v2) return a1[0] < a2[0]; return v1 > v2; }); for (auto [x, e, i] : v) { if(st.get(0, x)) necessary[i] = false; st.set(x, true); } st.reset(); sort(v.begin(), v.end(), [] (array<int, 3> a1, array<int, 3> a2) -> bool { int v1 = a1[1] - a1[0]; int v2 = a2[1] - a2[0]; if (v1 == v2) return a1[0] > a2[0]; return v1 > v2; }); for (auto [x, e, i] : v) { if (st.get(x+1, BOUND)) necessary[i] = false; st.set(x, true); } sort(v.begin(), v.end()); for (int i = 0; i < v.size(); i++) if (i+1 < v.size() && v[i][0] == v[i+1][0] && v[i][1] <= v[i+1][1]) necessary[v[i][2]] = false; int res = 0; for (int i = 0; i < n; i++) if (necessary[i]) res++; cout << res << "\n"; }

Compilation message (stderr)

Main.cpp: In constructor 'SegTree::SegTree(int, int)':
Main.cpp:9:22: warning: 'SegTree::data' will be initialized after [-Wreorder]
    9 |         vector<bool> data;
      |                      ^~~~
Main.cpp:8:21: warning:   'std::vector<int> SegTree::left' [-Wreorder]
    8 |         vector<int> left, right;
      |                     ^~~~
Main.cpp:10:9: warning:   when initialized here [-Wreorder]
   10 |         SegTree(int ll, int rr) : ll(ll), rr(rr), data(1, false), left(1, -1), right(1, -1) {}
      |         ^~~~~~~
Main.cpp: In member function 'void SegTree::set(int, int, int, int, int)':
Main.cpp:35:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |                 int m = l+r>>1;
      |                         ~^~
Main.cpp: In member function 'bool SegTree::get(int, int, int, int, int)':
Main.cpp:46:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |                 int m = l+r>>1;
      |                         ~^~
Main.cpp: In member function 'void SegTree::reset()':
Main.cpp:55:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |                 for (int i = 0; i < data.size(); i++)
      |                                 ~~^~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:105:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |         for (int i = 0; i < v.size(); i++)
      |                         ~~^~~~~~~~~~
Main.cpp:106:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |                 if (i+1 < v.size() && v[i][0] == v[i+1][0] && v[i][1] <= v[i+1][1]) necessary[v[i][2]] = false;
      |                     ~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...