QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#269780 | #5459. Goose, goose, DUCK? | pooty# | WA | 0ms | 3644kb | C++14 | 4.6kb | 2023-11-29 23:21:19 | 2023-11-29 23:21:19 |
Judging History
answer
#ifdef MY_LOCAL
#include "D://competitive_programming/debug/debug.h"
#define debug(x) cerr << "[" << #x<< "]:"<<x<<"\n"
#else
#define debug(x)
#endif
#define REP(i, n) for(int i = 0; i < (n); i ++)
#define REPL(i,m, n) for(int i = (m); i < (n); i ++)
#define SORT(arr) sort(arr.begin(), arr.end())
#define LSOne(S) ((S)&-(S))
#define sz(X) ((int)X.size())
#define READ(arr) for(auto &a: arr){cin>>a;}
#define SUM(arr) accumulate((arr).begin(), (arr).end(), 0LL)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;
const ll INF = 1e18;
class SegmentTree { // OOP style
private:
int n; // n = (int)A.size()
vii st;
vi lazy; // the arrays
int l(int p) { return p<<1; } // go to left child
int r(int p) { return (p<<1)+1; } // go to right child
ii conquer(ii p1, ii p2) {
auto [a1,b1] = p1;
auto [a2,b2] = p2;
if (a1 > a2) {
return p2;
} else if (a1 < a2) {
return p1;
} else {
return ii{a1, b1+b2};
}
// RMQ
}
void build(int p, int L, int R) { // O(n)
if (L == R) {
st[p] = {0,1}; // base case
} else {
int m = (L+R)/2;
build(l(p), L , m);
build(r(p), m+1, R);
st[p] = conquer(st[l(p)], st[r(p)]);
}
}
void propagate(int p, int L, int R) {
if (lazy[p] != 0) { // has a lazy flag
st[p].first += lazy[p]; // [L..R] has same value
if (L != R) {
lazy[l(p)] += lazy[p];
lazy[r(p)] += lazy[p];
} // L == R, a single index // time to update this
lazy[p] = 0; // erase lazy flag
}
}
ii RMQ(int p, int L, int R, int i, int j) { // O(log n)
propagate(p, L, R); // lazy propagation
if (L > j || R < i) return ii{INF, INF}; // infeasible
if ((L >= i) && (R <= j)) return st[p]; // found the segment
int m = (L+R)/2;
return conquer(RMQ(l(p), L , m, i , j),
RMQ(r(p), m+1, R, i, j ));
}
void update(int p, int L, int R, int i, int j, int val) { // O(log n)
propagate(p, L, R); // lazy propagation
if (L > j || R < i) return;
if ((L >= i) && (R <= j)) { // found the segment
lazy[p] += val; // update this
propagate(p, L, R); // lazy propagation
}
else {
int m = (L+R)/2;
update(l(p), L , m, i , j, val);
update(r(p), m+1, R, i, j , val);
st[p] = conquer(st[l(p)], st[r(p)]);
}
}
public:
SegmentTree(int sz) : n(sz), st(4*n), lazy(4*n, 0) {
build(1, 0, n-1);
}
void update(int i, int j, int val) { update(1, 0, n-1, i, j, val); }
ii RMQ(int i, int j) { return RMQ(1, 0, n-1, i, j); }
void dg(){
vii arr;
REP(i, n) {
arr.push_back(RMQ(i, i));
}
debug(arr);
}
};
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;cin>>n>>k;
vii arr1;
map<int, int> seen;
map<int, vi> posvec;
REP(i, n) {
int x;cin>>x;
int occ = seen[x];
seen[x]++;
posvec[x].push_back(i);
arr1.push_back({x, occ});
}
//debug(arr1);
//debug(posvec);
//debug(seen);
SegmentTree tr(n);
auto add_int = [&](int who, int firstocc, int val) {
//
vi &carr = posvec[who];
int ff = firstocc + k - 1;
if (sz(carr) <= ff) return;
int lbound = carr[ff];
int rbound = n - 1;
if (sz(carr) <= ff-1) {
rbound = carr[ff-1] - 1;
}
//debug(lbound);debug(rbound);
tr.update(lbound, rbound, val);
};
for (auto [x, ct]: seen) {
add_int(x, 0, 1);
}
//tr.dg();
auto get_ans = [&](int L) {
auto [a,b] = tr.RMQ(L, n-1);
//debug(a);debug(b);
if (a == 0) {
return b;
} return 0LL;
};
int ans = 0;
REP(i, n) {
int gg = get_ans(i);
//debug(gg);debug(i);
ans += gg;
auto [which, occ] = arr1[i];
add_int(which, occ, -1);
add_int(which, occ+1, 1);
}
cout<<ans<<"\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
6 2 1 2 2 1 3 3
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
6 1 1 2 3 4 5 6
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
100 10 142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...
output:
1943
result:
wrong answer 1st numbers differ - expected: '4309', found: '1943'