QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#121325#6626. Real Mountainslmeowdn0 9ms40824kbC++143.7kb2023-07-07 22:57:522023-07-07 22:57:55

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-07 22:57:55]
  • 评测
  • 测评结果:0
  • 用时:9ms
  • 内存:40824kb
  • [2023-07-07 22:57:52]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii; 
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=1e6+5,inf=0x3f3f3f3f3f3f3f3f,mod=1e6+3;
int n,a[N],b[N],c,s[N],t[N],ans,rt[N];
vi p[N];

struct priority_deque {
  int del[N],sz;
  priority_queue<int,vi,greater<int>> q1;
  priority_queue<int> q2;
  int front() {
    while(!q1.empty()) {
      int u=q1.top();
      if(!del[u]) return u;
      else q1.pop();
    } return -1;
  }
  int back() {
    while(!q2.empty()) {
      int u=q2.top();
      if(!del[u]) return u;
      else q2.pop();
    } return -1;
  }
  void erase(int x) {del[x]=1, --sz;}
  void insert(int x) {q1.push(x),q2.push(x),++sz;}
  int size() {return sz;}
} Q;

namespace SegT {
  int ls[N<<1],rs[N<<1],s[N<<1],tot=1;
  void build(int p,int l,int r) {
    if(l==r) {s[p]=a[l]; return;} int mid=l+r>>1;
    build(ls[p]=++tot,l,mid), build(rs[p]=++tot,mid+1,r);
    s[p]=min(s[ls[p]],s[rs[p]]);
  }
  void del(int p,int l,int r,int x) {
    if(l==r) {s[p]=inf; return;} int mid=l+r>>1;
    if(x<=mid) del(ls[p],l,mid,x); else del(rs[p],mid+1,r,x);
    s[p]=min(s[ls[p]],s[rs[p]]);
  }
  int qry(int p,int l,int r,int x,int y) {
    if(x>y) return inf;
    if(l==x&&r==y) return s[p]; int mid=l+r>>1;
    if(y<=mid) return qry(ls[p],l,mid,x,mid);
    else if(x>mid) return qry(rs[p],mid+1,r,mid+1,y);
    else return min(qry(ls[p],l,mid,x,mid),qry(rs[p],mid+1,r,mid+1,y));
  }
}

int sum(int x,int y) {return (x+y)*(y-x+1)/2;}

signed main() {
  n=read();
  rep(i,1,n) a[i]=read(), b[i]=a[i];
  sort(b+1,b+n+1); c=unique(b+1,b+n+1)-b-1;
  rep(i,1,n) {
    int x=lower_bound(b+1,b+c+1,a[i])-b;
    p[x].eb(i);
  }
  SegT::build(1,1,n);
  rep(i,1,n) s[i]=max(s[i-1],a[i]);
  per(i,n,1) t[i]=max(t[i+1],a[i]);
  rep(u,1,c-1) {
    int x=b[u], y=b[u+1];
    for(int i:p[u]) Q.insert(i);
    while(Q.size()) {
      int i=Q.front();
      if(s[Q.front()]<=x) Q.erase(i);
      else break;
    }
    while(Q.size()) {
      int i=Q.back();
      if(t[i]<=x) Q.erase(i);
      else break;
    }
    int m=Q.size();
    for(int i:p[u]) SegT::del(1,1,n,i);
    if(m>=1) {
      int l=Q.front(), r=Q.back();
      int A=SegT::qry(1,1,n,1,l-1);
      int B=SegT::qry(1,1,n,r+1,n);
      if(m==1) ans=(ans+sum(x,y-1)+(A+B)*(y-x))%mod;
      else {
        int C=SegT::qry(1,1,n,l+1,r-1);
        int rest=m*sum(x,y-1)+(m-2)*2*sum(x+1,y);
        rest+=min(A,min(B,C))*(y-x)+(A+B)*(y-x)+sum(x+1,y);
        ans=(ans+rest)%mod;
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 1ms
memory: 36404kb

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 1ms
memory: 38400kb

input:

3
62 20 71

output:

7287

result:

ok 1 number(s): "7287"

Test #3:

score: 0
Accepted
time: 0ms
memory: 36428kb

input:

10
72 33 22 22 13 49 53 57 72 85

output:

40403

result:

ok 1 number(s): "40403"

Test #4:

score: 0
Accepted
time: 2ms
memory: 38788kb

input:

5000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 97 97 97 97 9...

output:

481053

result:

ok 1 number(s): "481053"

Test #5:

score: 0
Accepted
time: 1ms
memory: 38656kb

input:

5000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 9ms
memory: 38692kb

input:

5000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

12595

result:

ok 1 number(s): "12595"

Test #7:

score: 0
Accepted
time: 6ms
memory: 38660kb

input:

5000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...

output:

299

result:

ok 1 number(s): "299"

Test #8:

score: 0
Accepted
time: 2ms
memory: 38880kb

input:

5000
100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

224232

result:

ok 1 number(s): "224232"

Test #9:

score: 0
Accepted
time: 1ms
memory: 38760kb

input:

5000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4...

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 5ms
memory: 38828kb

input:

5000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 9...

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: -3
Wrong Answer
time: 2ms
memory: 40824kb

input:

5000
100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4...

output:

496060

result:

wrong answer 1st numbers differ - expected: '499735', found: '496060'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%