QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133671 | #4936. Shopping Changes | Orange_JuiCE# | WA | 64ms | 11780kb | C++17 | 2.9kb | 2023-08-02 12:46:06 | 2023-08-02 12:46:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define rep(a, b, c) for(int (a)=(b);(a)<=(c);(a)++)
#define per(a, b, c) for(int (a)=(b);(a)>=(c);(a)--)
#define mset(var, val) memset(var,val,sizeof(var))
#define ll long long
#define int ll
#define fi first
#define se second
#define no "NO\n"
#define yes "YES\n"
#define pb push_back
#define endl "\n"
#define pii pair<int,int>
#define pll pair<ll,ll>
#define dbg(x...) do{cout<<#x<<" -> ";err(x);}while (0)
void err() { cout << '\n'; }
template<class T, class... Ts>
void err(T arg, Ts... args) {
cout << arg << ' ';
err(args...);
}
const int N = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int P = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);
struct node{
int x, id;
}c[N], w[N];
int n, m, L, ans1=0, ans2, mn;
int p[N], l[N], r[N];
void add(int x, int k, int nn) {
for(int i = x; i <= nn; i+=i&-i) p[i] += k;
}
int get(int x) {
int re = 0;
for(int i = x; i >= 1; i-=i&-i) re += p[i];
return re;
}
bool cmp1(node x, node y) {
return x.x < y.x;
}
// bool cmp2(node x, node y) {
// return x.id < y.id;
// }
int find1(int x) {
int l = 1, r = n, re = 0;
while(l <= r) {
int mid = (l+r)>>1;
if(c[mid].x >= x) r = mid-1;
else l = mid+1, re = mid;
}
return re;
}
int find2(int x) {
int l = 1, r = n, re = n+1;
while(l <= r) {
int mid = (l+r)>>1;
if(c[mid].x <= x) l = mid+1;
else r = mid-1, re = mid;
}
return re;
}
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> c[i].x;
c[i].id = i, p[i] = 0;
}
sort(c+1, c+1+n, cmp1);
for(int i = 1; i <= n; i++) {
ans1 += get(c[i].id);
add(1, 1, n);
add(c[i].id, -1, n);
}
// cout << ans1 << endl;
while(m--) {
cin >> L;
for(int i = 1; i <= L; i++) {
cin >> w[i].x;
w[i].id = i, p[i] = 0;
l[i] = find1(w[i].x);
r[i] = n-find2(w[i].x)+1;
// dbg(i,l[i], r[i]);
}
l[0] = l[L+1] = r[0] = r[L+1] = 0;
for(int i = 2; i <= L; i++) l[i] += l[i-1];
for(int i = L-1; i > 0; i--) r[i] += r[i+1];
ans2=0;
sort(w+1, w+1+L, cmp1);
for(int i = 1; i <= L; i++) {
ans2 += get(w[i].id);
add(1, 1, L);
add(w[i].id+1, -1, L);
}
int mn = l[0]+r[1];
for(int i = 1; i <= L; i++)
mn = min(mn, l[i]+r[i+1]);
// cout << ans2 << " " << mn << endl;
cout << ans1+ans2+mn << endl;
}
}
signed main() {
IOS;
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11780kb
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: 9628kb
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: 11660kb
input:
1 1 589284012 1 767928734
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 38ms
memory: 9644kb
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:
24802338 24830913 24857654 24813132 24846150 24785558 24857315 24805175 24862714 24785339 24804999 24780907 24808009 24798987 24958122 24781372 24772291 24846071 24953540 24778276 24778689 24979527 24770012 24892097 24776909 24865295 24821506 24772586 24800432 24891424 24864488 24820312 24801522 248...
result:
ok 9999 lines
Test #5:
score: 0
Accepted
time: 61ms
memory: 9800kb
input:
42320 25000 977178721 305456426 916831455 324594376 259922325 798438534 906876242 353428436 459214642 504133134 734517252 944888626 929971853 735313273 285979369 866298401 385768124 918185862 811827492 3054135 190006456 852394509 784943097 903969029 4089198 931644108 916374905 942243264 383987411 45...
output:
448869835 448857081 449001851 448984953 448766022 449088370 448752999 448813227 448791232 448952235 448991581 448762188 449564834 448895404 448773616 448827147 448822397 448871140 448785180 448915022 448786815 448758118 448930420 449164516 448765912 448826222 448791834 448895668 448789204 448791197 ...
result:
ok 25000 lines
Test #6:
score: -100
Wrong Answer
time: 64ms
memory: 9696kb
input:
50000 50000 478377125 98598664 834663974 414981508 481428682 921148788 327891419 311824685 274571883 326908479 516913707 230013528 47214051 844074075 870004539 261165376 338829696 476144552 905505033 857420851 4709519 198366271 90438077 24208873 865090108 250612383 910141082 205796257 712687049 6996...
output:
626276047 626281384 626305128 626284809 626194743 626223648 626345429 626232542 626201579 626246220 626205409 626202409 626200782 626281458 626203633 626200320 626196784 626209588 626202531 626221985 626236633 626240923 626221576 626193668 626196148 626357476 626201485 626209638 626191038 626237252 ...
result:
wrong answer 1st lines differ - expected: '626276046', found: '626276047'