제출 #667553

#제출 시각아이디문제언어결과실행 시간메모리
667553mychecksedadFancy Fence (CEOI20_fancyfence)C++17
12 / 100
1 ms340 KiB
/* Author : Mychecksdead */ #include<bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef long double ld; #define MOD (1000000000+7) #define MOD1 (998244353) #define PI 3.1415926535 #define pb push_back #define setp() cout << setprecision(15) #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " is " << x << '\n'; const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20; int n, ls[N], rs[N]; ll w[N], h[N], pref[N]; ll comb2(ll x){ return (x*(x+1)/2) % MOD; } ll p(int l, int r){ if(l > 0) return pref[r] - pref[l - 1]; return pref[r]; } void solve(){ cin >> n; for(int i = 0; i < n; ++i) cin >> h[i]; for(int i = 0; i < n; ++i) cin >> w[i]; pref[0] = w[0]; for(int i = 1; i < n; ++i) pref[i] = pref[i - 1] + w[i]; deque<pair<int, int>> q; ls[0] = -1; q.pb({h[0], 0}); for(int i = 1; i < n; ++i){ while(!q.empty() && q.back().first >= h[i]) q.pop_back(); if(!q.empty()) ls[i] = q.back().second; else ls[i] = -1; q.pb({h[i], i}); } q.clear(); rs[n - 1] = n; q.pb({h[n - 1], n - 1}); for(int i = n - 2; i >= 0; --i){ while(!q.empty() && q.back().first > h[i]) q.pop_back(); if(!q.empty()) rs[i] = q.back().second; else rs[i] = n; q.pb({h[i], i}); } ll ans = 0; for(int i = 0; i < n; ++i){ ll a = (p(ls[i] + 1, i) * p(i, rs[i] - 1) % MOD); (ans += (a - comb2(w[i] - 1)) * comb2(h[i])) %= MOD; } cout << (ans + MOD) % MOD; } int main(){ cin.tie(0); ios::sync_with_stdio(0); // freopen("in.txt", "r", stdin); int T = 1, aa; // cin >> T;aa=T; while(T--){ // cout << "Case #" << aa-T << ": "; solve(); cout << '\n'; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:70:16: warning: unused variable 'aa' [-Wunused-variable]
   70 |     int T = 1, aa;
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...