QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#797773 | #3598. Early Orders | LaVuna47# | WA | 39ms | 43724kb | C++20 | 2.8kb | 2024-12-03 18:00:05 | 2024-12-03 18:00:06 |
Judging History
answer
/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
// sparse table with or binary operation
class SparseTable
{
public:
std::vector<std::vector<ll>> table;
std::vector<ll> log2;
SparseTable() {}
SparseTable(const std::vector<ll>& arr)
{
int n = arr.size();
int max_log = std::log2(n) + 1;
table.resize(n, std::vector<ll>(max_log));
log2.resize(n + 1);
log2[1] = 0;
for (int i = 2; i <= n; ++i) {
log2[i] = log2[i / 2] + 1;
}
for (int i = 0; i < n; ++i) {
table[i][0] = arr[i];
}
for (int j = 1; j < max_log; ++j) {
for (int i = 0; i + (1 << j) <= n; ++i) {
table[i][j] = min(table[i][j - 1], table[i + (1 << (j - 1))][j - 1]);
}
}
}
ll query(int L, int R) {
int j = log2[R - L + 1];
return min(table[L][j], table[R - (1 << j) + 1][j]);
}
};
int solve()
{
int n,k;
if(!(cin>>n>>k))return 1;
vector<ll> a(n);
vector<int> c(k+1,0);
FOR(i,0,n)cin>>a[i],c[a[i]]+=1;
a.pb(k+1);
SparseTable st(a);
vector<int>res;
vector<bool> in(n+1,false);
for(int l=0,r=0; l<n;)
{
r=max(l,r);
while(r<n && c[a[r]] > 1)
{
c[a[r]]-=1;
++r;
}
int mVal = st.query(l,r);
while(a[l]!=mVal)++l;
if(!in[mVal])in[mVal]=true,res.pb(mVal);
++l;
}
//assert(sz(res)==k);
for(auto item:res)cout<<item<<' ';
cout<<'\n';
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
//cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
{
break;
}
#ifdef ONPC
cout << "__________________________" << endl;
#endif
}
#ifdef ONPC
cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3868kb
input:
6 3 3 2 1 3 1 3
output:
2 1 3
result:
ok single line: '2 1 3 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
10 5 5 4 3 2 1 4 1 1 5 5
output:
3 2 1 4 5
result:
ok single line: '3 2 1 4 5 '
Test #3:
score: -100
Wrong Answer
time: 39ms
memory: 43724kb
input:
200000 100000 29798 79235 44935 20368 15319 34973 11273 40142 82579 68354 79772 77697 59566 18516 50787 76175 25710 47305 87751 59942 49064 26470 38196 44038 38745 39903 71503 18468 59632 23169 10201 26065 62767 44170 37027 69281 7161 62056 7829 13359 80329 68362 59458 6406 80936 96142 56500 57523 1...
output:
29798 11273 40142 68354 79772 18516 25710 47305 59942 26470 38196 38745 39903 71503 10201 26065 62767 44170 7161 62056 7829 13359 68362 6406 56500 57523 6629 21853 21246 52201 56121 2741 29933 72408 96953 849 22024 68285 86159 24582 9177 8756 52266 85993 1699 18069 29470 31014 36759 93564 3053 13483...
result:
wrong answer 1st lines differ - expected: '29798 11273 40142 68354 79772 ...6 42906 92073 84291 44638 91402', found: '29798 11273 40142 68354 79772 ... 42906 92073 84291 44638 91402 '