Submission #70809773
Source Code Expand
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, q; cin >> n >> q;
vector<int>a(n);
rep(i, n) cin >> a[i];
vector<pair<long long, int>> query;
rep(i, q) {
long long k; cin >> k;
query.push_back({ k - 1, i });
}
sort(allR(query));
vector<pair<int, int>> ans(q);
ordered_set<pair<int, int>> st;
for (int i = 0; i < n; i++) st.insert({ a[i], -i });
long long cnt = 0;
// 操作後に小さくなる
rep(l, n) {
st.erase({ a[l],-l });
long long lim = st.order_of_key({ a[l], -(1 << 30) });//未満の数
while (!query.empty()) {
auto[k, idx] = query.back();
long long k1 = k - cnt;
if (k1 >= lim) break;
// find_by_order : 0-indexed で k 番目に小さい値を指すイテレータを取得する
auto r = -(*st.find_by_order(k1)).second;
ans[idx] = { l,r };
query.pop_back();
}
cnt += lim;
}
// 操作して普遍
{
vector<int>c(n + 1, 0), idx(n + 1, -1);
P p;
rep(i, n) {
if (idx[a[i]] != -1) p = { idx[a[i]],i };
cnt += c[a[i]];
c[a[i]]++;
idx[a[i]] = i;
}
while (!query.empty()) {
auto[k, idx] = query.back();
if (k >= cnt)break;
ans[idx] = p;
query.pop_back();
}
}
// 操作して大きくなる
rrep(l, n) {
int offset = st.order_of_key({ a[l], 1 << 30 });//未満の数
while (!query.empty()) {
auto[k, idx] = query.back();
long long k1 = k - cnt + offset;
if (k1 >= st.size())break;
auto r = (*st.find_by_order(k1)).second;
ans[idx] = { l, r };
query.pop_back();
}
cnt += st.size() - offset;
st.insert({ a[l],l });
}
for (auto[l, r] : ans)cout << l + 1 << " " << r + 1 << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
G - One Time Swap 2 |
| User |
kwm_t |
| Language |
C++23 (GCC 15.2.0) |
| Score |
575 |
| Code Size |
2762 Byte |
| Status |
AC |
| Exec Time |
491 ms |
| Memory |
21452 KiB |
Compile Error
./Main.cpp: In function 'int main()':
./Main.cpp:89:32: warning: comparison of integer expressions of different signedness: 'long long int' and '__gnu_pbds::detail::bin_search_tree_set<std::pair<int, int>, __gnu_pbds::null_type, std::less<std::pair<int, int> >, __gnu_pbds::detail::tree_traits<std::pair<int, int>, __gnu_pbds::null_type, std::less<std::pair<int, int> >, __gnu_pbds::tree_order_statistics_node_update, __gnu_pbds::rb_tree_tag, std::allocator<char> >, std::allocator<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | if (k1 >= st.size())break;
| ~~~^~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
575 / 575 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
1 ms |
3480 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3596 KiB |
| 01_test_00.txt |
AC |
326 ms |
21340 KiB |
| 01_test_01.txt |
AC |
284 ms |
21452 KiB |
| 01_test_02.txt |
AC |
290 ms |
21300 KiB |
| 01_test_03.txt |
AC |
329 ms |
21292 KiB |
| 01_test_04.txt |
AC |
382 ms |
21300 KiB |
| 01_test_05.txt |
AC |
424 ms |
21284 KiB |
| 01_test_06.txt |
AC |
491 ms |
21380 KiB |
| 01_test_07.txt |
AC |
458 ms |
21276 KiB |
| 01_test_08.txt |
AC |
382 ms |
21312 KiB |
| 01_test_09.txt |
AC |
385 ms |
21300 KiB |
| 01_test_10.txt |
AC |
391 ms |
21276 KiB |
| 01_test_11.txt |
AC |
410 ms |
21372 KiB |
| 01_test_12.txt |
AC |
387 ms |
21280 KiB |
| 01_test_13.txt |
AC |
382 ms |
21296 KiB |
| 01_test_14.txt |
AC |
388 ms |
21300 KiB |
| 01_test_15.txt |
AC |
424 ms |
21364 KiB |
| 01_test_16.txt |
AC |
337 ms |
21392 KiB |
| 01_test_17.txt |
AC |
308 ms |
21296 KiB |
| 01_test_18.txt |
AC |
296 ms |
21376 KiB |
| 01_test_19.txt |
AC |
311 ms |
21372 KiB |
| 01_test_20.txt |
AC |
343 ms |
21296 KiB |
| 01_test_21.txt |
AC |
303 ms |
21280 KiB |
| 01_test_22.txt |
AC |
298 ms |
21360 KiB |
| 01_test_23.txt |
AC |
317 ms |
21340 KiB |
| 01_test_24.txt |
AC |
111 ms |
7980 KiB |
| 01_test_25.txt |
AC |
112 ms |
8168 KiB |
| 01_test_26.txt |
AC |
113 ms |
8164 KiB |
| 01_test_27.txt |
AC |
114 ms |
8052 KiB |
| 01_test_28.txt |
AC |
116 ms |
7972 KiB |
| 01_test_29.txt |
AC |
95 ms |
7968 KiB |