QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#327008 | #7904. Rainbow Subarray | jiajieshi | WA | 37ms | 14612kb | C++17 | 9.6kb | 2024-02-14 17:28:37 | 2024-02-14 17:28:37 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pss pair<string,string>
#define fi first
#define se second
#define pb push_back
#define un unsigned
#define ull unsigned long long
#define int_INF 0x3f3f3f3f
#define LL long long
#define ll_INF 0x3f3f3f3f3f3f3f3f
#define lb long double
#define db double
#define re return
#define pll pair<ll,ll>
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define debug(a) cout<<"debug: "<<(#a)<<" = "<<a<<'\n'
#define cer(a) cerr<<#a<<'='<<(a)<<"@ line"<<__LINE__<<endl
#define cer2(a,b) cerr<<#a<<'='<<(a)<<','<<#b<<'='<<(b)<<"@ line"<<__LINE__<<endl
#define cer3(a,b,c) cerr<<#a<<'='<<(a)<<','<<#b<<'='<<(b)<<','<<#c<<'='<<(c)<<','<<"@ line"<<__LINE__<<endl
#define pdd pair<db,db>
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define KV(x) #x << " = " << x << ";"
#define DEBUG DebugLine(__LINE__)
#pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
#pragma GCC target("avx","sse2")
using namespace std;
const int maxn=5e5+100;
const ll mode=998244353;
const ll mode2=1e9+7;
const ll inf=9223372036854775807;
const db eps=1e-6;
typedef pair<int,int> hashv;
mt19937 mrand(random_device{}());
hashv operator + (hashv a,hashv b) {
int c1=a.fi+b.fi,c2=a.se+b.se;
if (c1>=mode) c1-=mode;
if (c2>=mode2) c2-=mode2;
return mp(c1,c2);
}
hashv operator - (hashv a,hashv b) {
int c1=a.fi-b.fi,c2=a.se-b.se;
if (c1<0) c1+=mode;
if (c2<0) c2+=mode2;
return mp(c1,c2);
}
hashv operator * (hashv a,hashv b) {
return mp(1ll*a.fi*b.fi%mode,1ll*a.se*b.se%mode2);
}
int rnd(int x) { return mrand() % x;}
struct DebugLine {
explicit DebugLine(int lineno) { std::cerr << lineno << "L "; }
~DebugLine() { std::cerr << std::endl; }
template <typename T> DebugLine &operator<<(T &&v) {
std::cerr << std::forward<T>(v);
return *this;
}
};
double PI = 3.141592653;
double my_cos(double x){
return cos(x*PI / 180.0);
}
double my_sin(double x){
return sin(x*PI / 180.0);
}
double my_tan(double x){
return tan(x*PI / 180.0);
}
ll n,m,a[maxn];
ll sum,ans;
string str;
vector<int>vt;
int vis[maxn];
ll ksm(ll a,ll b,ll p)
{
ll res=1ll;
while(b)
{
if(b&1)
res=res*a%p;
b>>=1;
a=a*a%p;
}
return res;
}
struct Hash_char{
const ll mod=998244353, base=131;
ll p[maxn], g[maxn];
void getp(){
p[0]=1;
for(int i=1; i<maxn; i++){
p[i]=p[i-1]*base%mod;
}
}
LL Hash(char s[]){
int len=strlen(s+1);
g[0]=0, g[1]=s[1];
for(int i=2; i<=len; i++){
g[i]=(g[i-1]*base+s[i])%mod;
}
return g[len];
}
LL getLR(int l, int r){//µÃµ½s[l]-s[r]µÄhashÖµ
if(l>r) return 0;
LL ans=((g[r]-g[l-1]*p[r-l+1])%mod+mod)%mod;
return ans;
}
}T[2];
LL strfz(int pos, int l, int r){//pos:Õý·´´®,·×ªl, r¡£
LL ans=T[pos].getLR(1, l-1)*T[pos].p[n-l+1]%T[pos].mod;
LL res=T[pos^1].getLR(n-r+1, n-r+1+r-l)*T[pos].p[n-r]%T[pos].mod;
ans=ans+res+T[pos].getLR(r+1, n);
return ans%T[pos].mod;
}
template<const int T>
struct ModInt {
const static int mod = T;
int x;
ModInt(int x = 0) : x(x % mod) {}
ModInt(long long x) : x(int(x % mod)) {}
int val() { return x; }
ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
bool operator == (const ModInt &a) const { return x == a.x; };
bool operator != (const ModInt &a) const { return x != a.x; };
void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
void operator /= (const ModInt &a) { *this = *this / a; }
friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
friend ModInt operator * (int y, const ModInt &a){ return ModInt(1LL * y * a.x % mod);}
friend ModInt operator / (int y, const ModInt &a){ return ModInt(y) / a;}
friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}
ModInt pow(int64_t n) const {
if(n == 0) return 1;
ModInt res(1), mul(x);
while(n){
if (n & 1) res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
ModInt inv() const {
int a = x, b = mod, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
if (u < 0) u += mod;
return u;
}
};
using mint = ModInt<1000000007>;
ll ecgcd(ll a,ll b,ll& x,ll& y)
{
if(b==0)
{
x=1,y=0;
return a;
}
ll d=ecgcd(b,a%b,y,x);
y-=a/b*x;
return d;
}
class manacherWrapper
{
private:
int l_;
string s_;
public:
std::vector<int> p;
std::vector<int> b;
std::vector<int> s;
explicit manacherWrapper(string str)
{
auto l = str.size();
//rebuild
l_ = l;
s_.resize(((l_ + 1) << 1) | 1);
p.resize(((l_ + 1) << 1) | 1);
b.resize(l_);
s.resize(l_ + 1);
s_[0] = '$', s_[1] = '#';
for (int i = 0; i < l_; ++i)
s_[(i + 1) << 1] = str[i], s_[((i + 1) << 1) | 1] = '#';
l_ = (l_ + 1) << 1;
//calc p
int mx = 0, id;
for (int i = 0; i < l_; ++i)
{
if (mx > i)p[i] = std::min(p[(id << 1) - i], mx - i);
else p[i] = 1;
for (; s_[i - p[i]] == s_[i + p[i]]; p[i]++);
if (p[i] + i > mx)
{
mx = p[i] + i;
id = i;
}
}
//calc b and s
for (int i = 0; i < l; ++i)
{
auto lp = get(i);
b[i - (lp >> 1)] = std::max(b[i - (lp >> 1)], lp);
s[i - (lp >> 1)]++, s[i + 1]--;
if (i + 1 >= l)break;
lp = get(i, i + 1);
if (lp > 0)
{
b[i + 1 - (lp >> 1)] = std::max(b[i + 1 - (lp >> 1)], lp);
s[i + 1 - (lp >> 1)]++, s[i + 1]--;
}
}
for (int i = 1; i < l; ++i)
{
b[i] = std::max(b[i], b[i - 1] - 2);
s[i] += s[i - 1];
}
}
int get(int pos)
{
return (int) p[(pos + 1) << 1] - 1;
}
int get(int posl, int posr)
{
return (int) p[((posl + 1) << 1) | 1] - 1;
}
int longestBegin(int begin)
{
return b[begin];
}
int totalBegin(int begin)
{
return s[begin];
}
bool isPalindrome(int l,int r)
{
if (l > r)std::swap(l, r);
auto mid = (l + r) >> 1;
auto len = (r - l + 1);
return len & 1 ? get(mid) >= len : get(mid, mid + 1) >= len;
}
};
ll k;
ll pre[maxn],b[maxn];
ll check(int l,int r)
{
ll v=pre[r]-pre[l-1];
return v;
}
void solve()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
if(n==1)
{
cout<<1<<'\n';
return;
}
ans=1;
a[0]=0;
for(int i=n;i>=1;i--)
{
a[i]=a[i]-a[i-1];
}
for(int i=1;i<=n;i++)
{
b[i]=abs(a[i]-1);
}
for(int i=1;i<=n;i++)
{
pre[i]=pre[i-1]+b[i];
}
for(int i=1;i<=n;i++)
{
int l=i,r=n;
int pos=-1;
while(l<=r)
{
int mid=(l+r)>>1;
ll need=check(i,mid);
if(i==1)
need-=a[1];
if(need<=k)
{
pos=max(pos,mid);
l=mid+1;
}else r=mid-1;
}
if(pos==-1)
continue;
ll v=pos-i+1ll+(i!=1?1:0);
ans=max(ans,v);
}
cout<<ans<<'\n';
}
int main(){
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\JIAJIEASHI\\Desktop\\in.cpp","r",stdin);
// freopen("out.cpp","w",stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int test_case;
test_case=1;
cin>>test_case;
while(test_case--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9644kb
input:
5 7 5 7 2 5 5 4 11 7 6 0 100 3 4 5 99 100 5 6 1 1 1 1 1 5 50 100 200 300 400 500 1 100 3
output:
4 3 5 1 1
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 37ms
memory: 14612kb
input:
11102 2 167959139 336470888 134074578 5 642802746 273386884 79721198 396628655 3722503 471207868 6 202647942 268792718 46761498 443917727 16843338 125908043 191952768 2 717268783 150414369 193319712 6 519096230 356168102 262263554 174936674 407246545 274667941 279198849 9 527268921 421436316 3613460...
output:
1 3 3 2 5 6 7 2 4 1 3 1 1 3 2 2 7 7 6 6 1 6 6 2 3 3 1 5 6 6 3 4 3 8 3 7 5 6 2 1 4 3 1 2 4 5 4 4 4 1 4 5 1 6 3 5 4 6 1 6 3 3 1 4 4 4 3 2 2 4 2 3 9 1 5 3 2 4 5 1 5 5 4 3 8 4 3 6 2 4 4 7 5 3 5 2 1 4 2 4 3 4 6 1 3 1 2 2 5 4 1 6 7 1 7 4 5 4 5 8 5 7 3 2 7 4 5 5 2 6 2 4 1 5 4 3 2 2 4 1 2 1 4 4 6 3 6 3 2 3 ...
result:
wrong answer 2nd lines differ - expected: '4', found: '3'