# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
310998 | 2020-10-09T02:50:54 Z | urd05 | Fancy Fence (CEOI20_fancyfence) | C++14 | 103 ms | 9324 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]+1,i)); } set<long long> s; long long sum=0; for(int i=0;i<n;i++) { scanf("%lld",&w[i]); sum+=w[i]; if (i) { pos[i]=pos[i-1]+w[i-1]; } } s.insert(0); s.insert(sum); sum%=mod; 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; s.insert(p); s.insert(p+w[pq.top().second]); pq.pop(); } long long len=now; ret+=(save*(((len*(len+mod-1))%mod)*inv2)%mod)%mod; len=prev; ret-=(save*(((len*(len+mod-1))%mod)*inv2)%mod)%mod; ret%=mod; ret+=mod; ret%=mod; prev=now; } printf("%lld",ret); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Incorrect | 1 ms | 384 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 47 ms | 4848 KB | Output is correct |
4 | Correct | 103 ms | 9324 KB | Output is correct |
5 | Correct | 98 ms | 9288 KB | Output is correct |
6 | Correct | 88 ms | 9324 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Incorrect | 1 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Incorrect | 2 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Incorrect | 1 ms | 384 KB | Output isn't correct |