답안 #661306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
661306 2022-11-25T12:47:40 Z ktkerem Fancy Fence (CEOI20_fancyfence) C++17
100 / 100
82 ms 6052 KB
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
/**/
//typedef int ll;
typedef long long ll;
typedef unsigned long long ull;
typedef std::string str;
/*typedef __int128 vll;
typedef unsigned __int128 uvll;*/
#define llll std::pair<ll , ll>
#define pb push_back
#define pf push_front
#define halo cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e9 + 7; 
const ll ous = 1e5 + 7;
const ll dx[4] = {-1 , 0 , 1 , 0} , dy[4] = {0,1,0,-1};
ll n , m;std::vector<llll> ar;
ll binpow(ll x , ll y){
    ll g = 1;
    while(y){
        if(y & 1){
            g*=x;
            g%=limit;
        }
        y/=2;
        x*=x;
        x%=limit;
    }
    return g;
}
void solve(){
    ll n;std::cin >> n;
    ar.resize(n+1);
    ll biki = binpow(2 , limit - 2);
    //std::cout << biki << "\n";
    for(ll i = 0;n>i;i++){
        std::cin >> ar[i].fi;
    }
    for(ll i = 0;n>i;i++){
        std::cin >> ar[i].sec;
    }
    ar[n] = {0 , 0};
    std::vector<llll> v;
    v.pb({0 , 0});
    ll ans = 0;
    for(ll i = 0;n>=i;i++){
        ll ww = 0;
        while(v[(ll)v.size() - 1].fi > ar[i].fi){
            ll nh = std::max(ar[i].fi , v[(ll)v.size() - 2].fi);
            ll df = v[(ll)v.size() - 1].fi - nh;
            ww = (ww + v[(ll)v.size() - 1].sec) % limit;
            v.pop_back();
            //std::cout << df << " " << ww << "\n";
            ans += (((((df * (df + 1) % limit) * biki % limit) + (df * nh % limit)) % limit) * ((ww * (ww + 1) % limit) * biki % limit))%limit;
            ans %= limit;
        }
        v.pb({ar[i].fi , ar[i].sec + ww});
    }
    std::cout << ans << "\n";
    return;/**/
}
signed main(){
    ll t=1;
    //std::cin >> t;
    ll o = 1;
    while(t--){ 
        //cout << "Case " << o++ << ":\n";
        solve();
    }
    return 0;
}/**/

Compilation message

fancyfence.cpp:5:78: warning: "/*" within comment [-Wcomment]
    5 | #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
      |                                                                               
fancyfence.cpp: In function 'int main()':
fancyfence.cpp:72:8: warning: unused variable 'o' [-Wunused-variable]
   72 |     ll o = 1;
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 28 ms 2304 KB Output is correct
4 Correct 54 ms 5172 KB Output is correct
5 Correct 52 ms 4132 KB Output is correct
6 Correct 51 ms 3384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 8 ms 1048 KB Output is correct
3 Correct 38 ms 3108 KB Output is correct
4 Correct 75 ms 5928 KB Output is correct
5 Correct 80 ms 6052 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 9 ms 1080 KB Output is correct
4 Correct 37 ms 3104 KB Output is correct
5 Correct 75 ms 5924 KB Output is correct
6 Correct 82 ms 6048 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 10 ms 1048 KB Output is correct
9 Correct 39 ms 3212 KB Output is correct
10 Correct 72 ms 5792 KB Output is correct
11 Correct 81 ms 5932 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 296 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 336 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 27 ms 2216 KB Output is correct
12 Correct 54 ms 5152 KB Output is correct
13 Correct 53 ms 4132 KB Output is correct
14 Correct 50 ms 3384 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 9 ms 1080 KB Output is correct
17 Correct 38 ms 3108 KB Output is correct
18 Correct 75 ms 5932 KB Output is correct
19 Correct 78 ms 6052 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 8 ms 980 KB Output is correct
22 Correct 40 ms 3116 KB Output is correct
23 Correct 72 ms 5804 KB Output is correct
24 Correct 74 ms 5936 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 308 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 8 ms 664 KB Output is correct
31 Correct 9 ms 664 KB Output is correct
32 Correct 36 ms 1948 KB Output is correct
33 Correct 37 ms 1972 KB Output is correct
34 Correct 69 ms 3512 KB Output is correct
35 Correct 71 ms 3632 KB Output is correct
36 Correct 74 ms 3788 KB Output is correct
37 Correct 75 ms 3776 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 75 ms 3764 KB Output is correct
40 Correct 73 ms 3800 KB Output is correct
41 Correct 74 ms 4144 KB Output is correct
42 Correct 75 ms 4900 KB Output is correct