QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208502 | #4936. Shopping Changes | Beevo# | WA | 82ms | 3992kb | C++23 | 1.8kb | 2023-10-09 17:58:40 | 2023-10-09 17:58:41 |
Judging History
answer
#include <bits/stdc++.h>
#define el '\n'
#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll INF = 1e18;
const int N = 2e5 + 5;
ll cntC;
ordered_multiset<int> st;
int n, l, c[N], w[N];
ll solve(int m) {
ll cnt = 0;
for (int i = 0; i < m; i++)
cnt += lower_bound(c, c + n, w[i]) - c;
for (int i = m; i < l; i++)
cnt += n - (upper_bound(c, c + n, w[i]) - c);
return cnt;
}
void testCase() {
int m;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> c[i], cntC += st.size() - st.order_of_key(c[i] + 1), st.insert(c[i]);
sort(c, c + n);
int s, e, m1, m2;
ll sol, sol1, sol2, curCnt;
for (int i = 0; i < m; i++) {
cin >> l;
st.clear();
curCnt = 0;
for (int j = 0; j < l; j++)
cin >> w[j], curCnt += st.size() - st.order_of_key(w[j] + 1), st.insert(w[j]);
s = 0, e = l, sol = INF;
while (s <= e) {
m1 = s + (e - s) / 3;
m2 = e - (e - s) / 3;
sol1 = solve(m1), sol2 = solve(m2);
sol = min({sol, sol1, sol2});
if (sol1 < sol2)
e = m2 - 1;
else
s = m1 + 1;
}
cout << cntC + curCnt + sol << el;
}
}
signed main() {
Beevo
int t = 1;
// cin >> t;
while (t--)
testCase();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3628kb
input:
3 3 5 6 7 6 2 3 4 8 9 10 2 100 99 3 5 6 7
output:
0 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
3 2 7 6 5 6 2 3 4 8 9 10 6 10 9 8 4 3 2
output:
3 27
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
1 1 589284012 1 767928734
output:
0
result:
ok single line: '0'
Test #4:
score: -100
Wrong Answer
time: 82ms
memory: 3992kb
input:
10000 9999 298772847 712804102 869795012 527998188 804246450 598105371 843966934 639805471 937482040 887551242 254734680 188704975 17408126 626523673 553956319 697723205 231690822 637079761 232393146 377026277 962223856 338922458 912529500 710873344 942955137 51167037 195729799 529674367 990599310 4...
output:
24808384 24830913 24858920 24813132 24846150 24785558 24858029 24805175 24862714 24791589 24805291 24780907 24808009 24805985 24958122 24784440 24772291 24846071 24963894 24778276 24778689 24979527 24770012 24892097 24776909 24865295 24821506 24772586 24803412 24892218 24865194 24827624 24801522 248...
result:
wrong answer 1st lines differ - expected: '24802338', found: '24808384'