QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209798 | #7102. Live Love | PetroTarnavskyi# | RE | 0ms | 0kb | C++17 | 2.6kb | 2023-10-10 17:31:26 | 2023-10-10 17:31:26 |
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
typedef tree<PII, null_type, less<PII>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int INF = 1'000'000'747;
const int N = 100'447;
struct node
{
int sz;
ordered_set s;
LL ans;
node()
{
sz = 0;
ans = 0;
}
void clear()
{
sz = 0;
ans = 0;
s.clear();
}
void addR(int x, int i)
{
ans += sz - s.order_of_key({x, INF});
s.insert({x, i});
sz++;
}
void addL(int x, int i)
{
ans += s.order_of_key({x, -1});
s.insert({x, i});
sz++;
}
void removeR(int x, int i)
{
sz--;
s.erase({x, i});
ans -= sz - s.order_of_key({x, INF});
}
void removeL(int x, int i)
{
sz--;
s.erase({x, i});
ans -= s.order_of_key({x, -1});
}
};
node A[N];
void solve()
{
int n;
cin >> n;
int idx = 1;
map<int, int> s;
multiset<LL> ans;
VI a(n);
FOR (i, 0, n)
{
cin >> a[i];
A[0].addR(a[i], i);
}
s[0] = 0;
s[n] = -1;
ans.insert(A[0].ans);
LL z = 0;
FOR (i, 0, n)
{
z = *prev(ans.end());
if (i)
cout << ' ';
cout << z;
cerr << z << endl;
LL p;
cin >> p;
p ^= z;
p--;
auto it = prev(s.upper_bound(p));
int l = it->F;
int r = next(it)->F - 1;
int id = it->S;
ans.erase(ans.find(A[id].ans));
s.erase(p);
if (p - l <= r - p)
{
FOR (j, l, p)
{
A[id].removeL(a[j], j);
A[idx].addR(a[j], j);
}
A[id].removeL(a[p], p);
s[l] = idx;
ans.insert(A[idx].ans);
s[p + 1] = id;
ans.insert(A[id].ans);
}
else
{
RFOR (j, r + 1, p + 1)
{
A[id].removeR(a[j], j);
A[idx].addL(a[j], j);
}
A[id].removeR(a[p], p);
s[l] = idx;
ans.insert(A[idx].ans);
s[p + 1] = id;
ans.insert(A[id].ans);
//cerr << "2 ";
//cerr << tmp.ans << ' ' << nd.ans << '\n';
}
idx++;
s[p] = -1;
}
FOR (i, 0, n)
{
A[i].clear();
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
while (t--)
{
solve();
}
cerr << double(clock()) / CLOCKS_PER_SEC << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
5 5 4 100 50 252 52 3 0 10 10
output:
3 3 1