Submission #310994

# Submission time Handle Problem Language Result Execution time Memory
310994 2020-10-09T02:22:49 Z urd05 Fancy Fence (CEOI20_fancyfence) C++14
0 / 100
1 ms 388 KB
#include <bits/stdc++.h>
using namespace std;

long long h[100000];
long long w[100000];
long long pos[100000];
typedef pair<int,int> P;
priority_queue<P,vector<P>,greater<P>> pq;
const int mod=1e9+7;
long long inv2=5e8+4;

int main(void) {
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        scanf("%lld",&h[i]);
        pq.push(P(h[i],i));
    }
    set<long long> s;
    long long sum=0;
    for(int i=0;i<n;i++) {
        scanf("%lld",&w[i]);
        sum+=w[i];
        sum%=mod;
        if (i) {
            pos[i]=pos[i-1]+w[i-1];
        }
    }
    s.insert(0);
    s.insert(sum);
    long long pl=(sum*(sum+1))/2;
    pl%=mod;
    long long prev=0;
    long long ret=0;
    while (!pq.empty()) {
        long long save=pl;
        int now=pq.top().first;
        while (!pq.empty()&&pq.top().first==now) {
            long long p=pos[pq.top().second];
            long long d=*(--(s.upper_bound(p)));
            long long u=*s.lower_bound(p+w[pq.top().second]);
            long long len=(u-d)%mod;
            pl-=(((len*(len+1))%mod)*inv2)%mod;
            len=(p-d)%mod;
            pl+=(((len*(len+1))%mod)*inv2)%mod;
            len=(u-p-w[pq.top().second])%mod;
            pl+=(((len*(len+1))%mod)*inv2)%mod;
            pl%=mod;
            pl+=mod;
            pl%=mod;
            pq.pop();
        }
        long long len=now;
        ret+=(save*(((len*(len+1))%mod)*inv2)%mod)%mod;
        len=prev;
        ret-=(save*(((len*(len+1))%mod)*inv2)%mod)%mod;
        ret%=mod;
        ret+=mod;
        ret%=mod;
        prev=now;
    }
    printf("%lld",ret);
}

Compilation message

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
fancyfence.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |         scanf("%lld",&h[i]);
      |         ~~~~~^~~~~~~~~~~~~~
fancyfence.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |         scanf("%lld",&w[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct