Submission #1144726

#TimeUsernameProblemLanguageResultExecution timeMemory
1144726Muaath_5케이크 (CEOI14_cake)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define int ll #define pii pair<int, int> const int N = 5e5+1; // Use template for ordered_set to avoid namespace issues template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int n, a, d[N]; #define seg pii seg tree[4*N]; seg INF = {1e9, 1e9}; // Update function with proper indentation void update(int idx, seg val, int l = 1, int r = n, int node = 1) { if (l == r) { tree[node] = val; return; } const int mid = (l + r) / 2; if (idx <= mid) update(idx, val, l, mid, node * 2); else update(idx, val, mid + 1, r, node * 2 + 1); tree[node] = min(tree[node * 2], tree[node * 2 + 1]); } // Query function with proper indentation seg query(int ql, int qr, int l = 1, int r = n, int node = 1) { if (ql <= l && r <= qr) return tree[node]; if (l > qr || r < ql) return INF; const int mid = (l + r) / 2; return min( query(ql, qr, l, mid, node * 2), query(ql, qr, mid + 1, r, node * 2 + 1) ); } seg cc[N]; map<int, int> cmp; int g[N]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> a; // Read input array for (int i = 1; i <= n; i++) { cin >> d[i]; } ordered_set<pair<int, int>> oleft, oright; // Initialize left side of 'a' for (int i = 1; i < a; i++) { cc[i] = {n - d[i] + 1, 0}; oleft.insert(cc[i]); update(i, cc[i]); } // Initialize right side of 'a' for (int i = a + 1; i <= n; i++) { cc[i] = {n - d[i] + 1, 0}; oright.insert(cc[i]); update(i, cc[i]); } int q; cin >> q; int ttt = 1; while (q--) { ttt++; char t; int i, e; cin >> t >> i; if (t == 'F') { // Simplified handling of 'F' query if (a == 1 || a == n) { cout << abs(a - i) << '\n'; continue; } if (i == a) { cout << "0\n"; continue; } if (i < a) { auto suff_max = query(i, a - 1); cout << (a - i) + oright.size() - oright.order_of_key(suff_max) << '\n'; } else { // i > a auto pref_max = query(a + 1, i); cout << (i - a) + oleft.size() - oleft.order_of_key(pref_max) << '\n'; } } else { // Update query cin >> e; // Remove from previous set if (i < a) oleft.erase(cc[i]); if (i > a) oright.erase(cc[i]); // Update value cc[i] = {e, -ttt}; update(i, cc[i]); // Re-insert into appropriate set if (i < a) oleft.insert(cc[i]); if (i > a) oright.insert(cc[i]); } } return 0; }

Compilation message (stderr)

cake.cpp: In function 'void update(long long int, std::pair<long long int, long long int>, long long int, long long int, long long int)':
cake.cpp:27:9: error: reference to 'tree' is ambiguous
   27 |         tree[node] = val;
      |         ^~~~
In file included from cake.cpp:2:
/usr/include/c++/11/ext/pb_ds/assoc_container.hpp:635:9: note: candidates are: 'template<class Key, class Mapped, class Cmp_Fn, class Tag, template<class Node_CItr, class Node_Itr, class Cmp_Fn_, class _Alloc_> class Node_Update, class _Alloc> class __gnu_pbds::tree'
  635 |   class tree : public PB_DS_TREE_BASE
      |         ^~~~
cake.cpp:21:5: note:                 'std::pair<long long int, long long int> tree [2000004]'
   21 | seg tree[4*N];
      |     ^~~~
cake.cpp:36:5: error: reference to 'tree' is ambiguous
   36 |     tree[node] = min(tree[node * 2], tree[node * 2 + 1]);
      |     ^~~~
In file included from cake.cpp:2:
/usr/include/c++/11/ext/pb_ds/assoc_container.hpp:635:9: note: candidates are: 'template<class Key, class Mapped, class Cmp_Fn, class Tag, template<class Node_CItr, class Node_Itr, class Cmp_Fn_, class _Alloc_> class Node_Update, class _Alloc> class __gnu_pbds::tree'
  635 |   class tree : public PB_DS_TREE_BASE
      |         ^~~~
cake.cpp:21:5: note:                 'std::pair<long long int, long long int> tree [2000004]'
   21 | seg tree[4*N];
      |     ^~~~
cake.cpp:36:22: error: reference to 'tree' is ambiguous
   36 |     tree[node] = min(tree[node * 2], tree[node * 2 + 1]);
      |                      ^~~~
In file included from cake.cpp:2:
/usr/include/c++/11/ext/pb_ds/assoc_container.hpp:635:9: note: candidates are: 'template<class Key, class Mapped, class Cmp_Fn, class Tag, template<class Node_CItr, class Node_Itr, class Cmp_Fn_, class _Alloc_> class Node_Update, class _Alloc> class __gnu_pbds::tree'
  635 |   class tree : public PB_DS_TREE_BASE
      |         ^~~~
cake.cpp:21:5: note:                 'std::pair<long long int, long long int> tree [2000004]'
   21 | seg tree[4*N];
      |     ^~~~
cake.cpp:36:38: error: reference to 'tree' is ambiguous
   36 |     tree[node] = min(tree[node * 2], tree[node * 2 + 1]);
      |                                      ^~~~
In file included from cake.cpp:2:
/usr/include/c++/11/ext/pb_ds/assoc_container.hpp:635:9: note: candidates are: 'template<class Key, class Mapped, class Cmp_Fn, class Tag, template<class Node_CItr, class Node_Itr, class Cmp_Fn_, class _Alloc_> class Node_Update, class _Alloc> class __gnu_pbds::tree'
  635 |   class tree : public PB_DS_TREE_BASE
      |         ^~~~
cake.cpp:21:5: note:                 'std::pair<long long int, long long int> tree [2000004]'
   21 | seg tree[4*N];
      |     ^~~~
cake.cpp: In function 'std::pair<long long int, long long int> query(long long int, long long int, long long int, long long int, long long int)':
cake.cpp:42:16: error: reference to 'tree' is ambiguous
   42 |         return tree[node];
      |                ^~~~
In file included from cake.cpp:2:
/usr/include/c++/11/ext/pb_ds/assoc_container.hpp:635:9: note: candidates are: 'template<class Key, class Mapped, class Cmp_Fn, class Tag, template<class Node_CItr, class Node_Itr, class Cmp_Fn_, class _Alloc_> class Node_Update, class _Alloc> class __gnu_pbds::tree'
  635 |   class tree : public PB_DS_TREE_BASE
      |         ^~~~
cake.cpp:21:5: note:                 'std::pair<long long int, long long int> tree [2000004]'
   21 | seg tree[4*N];
      |     ^~~~