QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#790166 | #2448. Make Rounddog Happy | ainta | WA | 351ms | 9816kb | C++23 | 3.3kb | 2024-11-28 03:19:06 | 2024-11-28 03:19:07 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define rep(i,b) rng(i,0,b-1)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
#define per(i,b) gnr(i,b-1,0)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long ll;
using pii=pair<int,int>;
using vi=vc<int>;
using uint=unsigned;
using ull=unsigned long long;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using t3=tuple<int,int,int>;
ll rand_int(ll l, ll r) { //[l, r]
#ifdef LOCAL
static mt19937_64 gen;
#else
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
#endif
return uniform_int_distribution<ll>(l, r)(gen);
}
template <uint MD> struct ModInt {
using M = ModInt;
const static M G;
uint v;
ModInt(ll _v = 0) { set_v(_v % MD + MD); }
M& set_v(uint _v) {
v = (_v < MD) ? _v : _v - MD;
return *this;
}
explicit operator bool() const { return v != 0; }
M operator-() const { return M() - *this; }
M operator+(const M& r) const { return M().set_v(v + r.v); }
M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
M operator/(const M& r) const { return *this * r.inv(); }
M& operator+=(const M& r) { return *this = *this + r; }
M& operator-=(const M& r) { return *this = *this - r; }
M& operator*=(const M& r) { return *this = *this * r; }
M& operator/=(const M& r) { return *this = *this / r; }
bool operator==(const M& r) const { return v == r.v; }
M pow(ll n) const {
M x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
M inv() const { return pow(MD - 2); }
friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<998244353>;
#define N_ 301000
const int SZ = (1<<19);
int n, K, w[N_], M[N_], E[N_], P[N_];
int BIT[N_];
void Add(int a, int b){
while(a<N_){
BIT[a]+=b;
a+=(a&-a);
}
}
int Sum(int a){
int r=0;
while(a){
r+=BIT[a];
a-=(a&-a);
}
return r;
}
ll Do(int b, int e){
if(e==b){
if(w[b]-1 <= K)return 1;
return 0;
}
int m = (b+e)/2;
ll res = Do(b,m) + Do(m+1,e);
M[m+1]=0;
gnr(i,m,b){
M[i]=max(M[i+1],w[i]);
}
rng(i,b,e)P[w[i]]=0;
rng(i,b,m){
E[i]=max(m+1, M[i]-K+i-1);
P[w[i]]=i;
Add(E[i],1);
}
int pv = b, r = m, MM = 0;
rng(i,m+1,e){
if(P[w[i]]>m)break;
if(r<m){
r++;
Add(E[r],1);
}
MM=max(MM,w[i]);
while(r>=b && i-r+1 < MM-K){
Add(E[r],-1);
r--;
}
while(pv<=P[w[i]]){
Add(E[pv],-1);
pv++;
}
P[w[i]]=i;
if(pv<=r){
res += Sum(i);
}
}
while(pv<=m){Add(E[pv],-1);pv++;}
while(r<m){r++;Add(E[r],1);}
return res;
}
void Solve(){
scanf("%d%d",&n,&K);
rng(i,1,n){
scanf("%d",&w[i]);
}
printf("%lld\n",Do(1,n));
}
int main(){
int TC=1;
scanf("%d",&TC);
rng(T,1,TC){
Solve();
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 351ms
memory: 9816kb
input:
13 10000 9950 8745 9998 467 7434 1964 9375 9997 48 8597 2568 3761 9498 1576 6348 4819 4870 9997 9043 8623 2147 8768 9555 9709 2657 5124 2631 3010 2249 2212 2997 9996 4320 796 5189 5556 5548 5290 2026 5555 187 9090 9149 908 8714 5238 3236 3986 5510 8571 3020 5118 2522 2465 384 9105 1342 8220 8291 672...
output:
488723 4 6739 3109 9670 491846 5 7641 3208 360 356005371 658544243 662429273
result:
wrong answer 1st lines differ - expected: '224745', found: '488723'