Submission #1282971

#TimeUsernameProblemLanguageResultExecution timeMemory
1282971TVSownFancy Fence (CEOI20_fancyfence)C++20
25 / 100
1096 ms1848 KiB
///*** Sown_Vipro ***/// /// ->TEAM SELECTION TEST<- /// #include<bits/stdc++.h> using namespace std; //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") #define F first #define S second #define pb push_back #define pi pair<int, int> #define pii pair<int, pair<int, int> > #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define REP(i, a, b) for(int i = a; i >= b; --i) #define all(s) s.begin(), s.end() #define szz(s) int(s.size()) const string NAME = "sown"; const int N = 1e6 + 5, MAX = 1e6, MOD = 1e9 + 7; void maxi(int &x, int y){ if(x < y) x = y; } void mini(int &x, int y){ if(x > y) x = y; }; void add(int &x, int y){ x += y; x += MOD * (x < 0); x -= MOD * (x >= MOD); }; int n; int h[N], w[N]; long long s[N]; void solve(){ cin >> n; FOR(i, 1, n) cin >> h[i]; FOR(i, 1, n){ cin >> w[i]; s[i] = (s[i - 1] + w[i]) % MOD; } vector<int> st; st.pb(0); int res = 0; FOR(i, 1, n){ while(h[st.back()] >= h[i]){ st.pop_back(); } int j = szz(st) - 1, last = i - 1; int A = 1ll * h[i] * (h[i] + 1) % MOD * 500000004 % MOD; int B = 1ll * w[i] * (w[i] + 1) % MOD * 500000004 % MOD; res = (res + 1ll * A * B) % MOD; REP(H, h[i], 1){ while(h[st[j]] >= H) --j; long long W = s[last] - s[st[j]]; // cout << i << " " << H << " " << w[i] << " " << last << " " << st[j] << " " << W << "\n"; int A = 1ll * H * (H + 1) % MOD * 500000004 % MOD; int B = 1ll * w[i] * W % MOD; res = (res + 1ll * A * B) % MOD; last = st[j]; } st.pb(i); } cout << res; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if(fopen((NAME + ".inp").c_str(), "r")){ freopen((NAME + ".inp").c_str(), "r", stdin); freopen((NAME + ".out").c_str(), "w", stdout); } int t = 1; // cin >> t; while(t--){ solve(); } }

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fancyfence.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...