QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#209729 | #7102. Live Love | PetroTarnavskyi# | WA | 0ms | 3660kb | C++17 | 2.4kb | 2023-10-10 16:52:54 | 2023-10-10 16:52:55 |
Judging History
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 = 1000'000'747;
struct node
{
int sz;
ordered_set s;
LL ans;
node()
{
sz = 0;
ans = 0;
}
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});
}
};
void solve()
{
int n;
cin >> n;
map<int, node> s;
multiset<LL> ans;
VI a(n);
node nod;
FOR (i, 0, n)
{
cin >> a[i];
nod.addR(a[i], i);
}
s[0] = nod;
s[n] = node();
ans.insert(nod.ans);
int z = 0;
FOR (i, 0, n)
{
z = *prev(ans.end());
if (i)
cout << ' ';
cout << z;
int p;
cin >> p;
p ^= z;
p--;
auto it = prev(s.upper_bound(p));
int l = it->F;
int r = next(it)->F - 1;
node nd;
swap(nd, it->S);
ans.erase(ans.find(nd.ans));
s.erase(p);
if (p - l <= r - p)
{
node tmp;
FOR (j, l, p)
{
nd.removeL(a[j], j);
tmp.addR(a[j], j);
}
nd.removeL(a[p], p);
s[l] = tmp;
ans.insert(tmp.ans);
s[p + 1] = nd;
ans.insert(nd.ans);
}
else
{
node tmp;
RFOR (j, r + 1, p + 1)
{
nd.removeR(a[j], j);
tmp.addL(a[j], j);
}
nd.removeR(a[p], p);
s[l] = nd;
ans.insert(nd.ans);
s[p + 1] = tmp;
ans.insert(tmp.ans);
//cerr << "2 ";
//cerr << tmp.ans << ' ' << nd.ans << '\n';
}
s[p] = node();
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3660kb
input:
5 5 4 100 50 252 52 3 0 10 10
output:
3 3 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1
result:
wrong answer 1st lines differ - expected: '4 2', found: '3 3 1 1 1'