Submission #1008249

#TimeUsernameProblemLanguageResultExecution timeMemory
1008249kaysanFancy Fence (CEOI20_fancyfence)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define pp pop_back #define fi first #define se second #define lb lower_bound #define ub upper_bound #define pll pair<ll,ll> #define pii pair<int,int> #define vl vector<ll> #define nikah ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); const ll maxn = 1e5+7, modn1 = 1e9+7, modn2 = 998244353; using namespace std; // kalo kamu ngga emas nanti nadya merasa bersalah, ayo san demi nadya!!! // Kalo emang soalnya susah, pindah soal dulu // Jangan sampe diem, pikirin sesuatu, pasti bisa!!! // Cobain semua approach, jangan ngestuck di satu pemikiran // Jangan overthinking, jangan panik, tenangin pikiranmu ll t,n; ll h[maxn], w[maxn]; vector<ll>v,b; ll f (ll x) { return ((x * (x+1)) / 2) % modn1; } void solve () { v.pb(0); b.pb(0); cin>>n; for (ll i=1; i<=n; i++) { cin>>h[i]; } for (ll i=1; i<=n; i++) { cin>>w[i]; if (i>1) { if (h[i] != h[i-1]) { v.pb(h[i-1]); b.pb(w[i-1]); } else { w[i] += w[i-1]; } } } v.pb(h[n]); b.pb(w[n]); ll ans = 0, cur = 1, cnt = 0, N = v.size(); bool inc = 0, dec = 0; for (ll i=1; i<N; i++) { if (i == N - 1) { if (dec) { ll cnt2 = 0; for (ll j=i; j>=cur; j--) { cnt2 += b[j]; if (j == i) ans = (ans + ((f(b[j]) * f(v[j])) % modn1)) % modn1; else { ans = (ans + ((f(cnt2) * f(v[j])) % modn1)) % modn1; ans = (ans - ((f(cnt2 - b[j]) * f(v[j])) % modn1)) % modn1; } } dec = 0; } else { cnt += b[i]; if (inc == 0) ans = (ans + ((f(b[i]) * f(v[i])) % modn1)) % modn1; else { ans = (ans + ((f(cnt) * f(v[i])) % modn1)) % modn1; ans = (ans - ((f(cnt - b[i]) * f(v[i])) % modn1)) % modn1; } } } else if (v[i] > v[i+1]) { if (dec) { ll cnt2 = 0; for (ll j=i; j>=cur; j--) { cnt2 += b[j]; if (j == i) ans = (ans + ((f(b[j]) * f(v[j])) % modn1)) % modn1; else { ans = (ans + ((f(cnt) * f(v[j])) % modn1)) % modn1; ans = (ans - ((f(cnt - b[j]) * f(v[j])) % modn1)) % modn1; } } dec = 0; } else { cnt += b[i]; if (inc == 0) ans = (ans + ((f(b[i]) * f(v[i])) % modn1)) % modn1; else { ans = (ans + ((f(cnt) * f(v[i])) % modn1)) % modn1; ans = (ans - ((f(cnt - b[i]) * f(v[i])) % modn1)) % modn1; } } inc = 1; } else { if (!dec) { cur = i; inc = 0; cnt = 0; } dec = 1; } // cout<<i<<" : "<<ans<<endl; } while (ans < 0) ans += modn1; cout<<ans<<endl; } int main () { nikah t = 1; // cin>>t; while (t--) { solve(); // cout<<endl; } }#include <bits/stdc++.h> #define ll long long #define pb push_back #define pp pop_back #define fi first #define se second #define lb lower_bound #define ub upper_bound #define pll pair<ll,ll> #define pii pair<int,int> #define vl vector<ll> #define nikah ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); const ll maxn = 1e5+7, modn1 = 1e9+7, modn2 = 998244353; using namespace std; // kalo kamu ngga emas nanti nadya merasa bersalah, ayo san demi nadya!!! // Kalo emang soalnya susah, pindah soal dulu // Jangan sampe diem, pikirin sesuatu, pasti bisa!!! // Cobain semua approach, jangan ngestuck di satu pemikiran // Jangan overthinking, jangan panik, tenangin pikiranmu ll t,n; ll h[maxn], w[maxn]; vector<ll>v,b; ll f (ll x) { return ((x * (x+1)) / 2) % modn1; } void solve () { v.pb(0); b.pb(0); cin>>n; for (ll i=1; i<=n; i++) { cin>>h[i]; } for (ll i=1; i<=n; i++) { cin>>w[i]; if (i>1) { if (h[i] != h[i-1]) { v.pb(h[i-1]); b.pb(w[i-1]); } else { w[i] += w[i-1]; } } } v.pb(h[n]); b.pb(w[n]); ll ans = 0, cur = 1, cnt = 0, N = v.size(); bool inc = 0, dec = 0; for (ll i=1; i<N; i++) { if (i == N - 1) { if (dec) { ll cnt2 = 0; for (ll j=i; j>=cur; j--) { cnt2 += b[j]; if (j == i) ans = (ans + ((f(b[j]) * f(v[j])) % modn1)) % modn1; else { ans = (ans + ((f(cnt2) * f(v[j])) % modn1)) % modn1; ans = (ans - ((f(cnt2 - b[j]) * f(v[j])) % modn1)) % modn1; } } dec = 0; } else { cnt += b[i]; if (inc == 0) ans = (ans + ((f(b[i]) * f(v[i])) % modn1)) % modn1; else { ans = (ans + ((f(cnt) * f(v[i])) % modn1)) % modn1; ans = (ans - ((f(cnt - b[i]) * f(v[i])) % modn1)) % modn1; } } } else if (v[i] > v[i+1]) { if (dec) { ll cnt2 = 0; for (ll j=i; j>=cur; j--) { cnt2 += b[j]; if (j == i) ans = (ans + ((f(b[j]) * f(v[j])) % modn1)) % modn1; else { ans = (ans + ((f(cnt) * f(v[j])) % modn1)) % modn1; ans = (ans - ((f(cnt - b[j]) * f(v[j])) % modn1)) % modn1; } } dec = 0; } else { cnt += b[i]; if (inc == 0) ans = (ans + ((f(b[i]) * f(v[i])) % modn1)) % modn1; else { ans = (ans + ((f(cnt) * f(v[i])) % modn1)) % modn1; ans = (ans - ((f(cnt - b[i]) * f(v[i])) % modn1)) % modn1; } } inc = 1; } else { if (!dec) { cur = i; inc = 0; cnt = 0; } dec = 1; } // cout<<i<<" : "<<ans<<endl; } while (ans < 0) ans += modn1; cout<<ans<<endl; } int main () { nikah t = 1; // cin>>t; while (t--) { solve(); // cout<<endl; } }

Compilation message (stderr)

fancyfence.cpp:116:2: error: stray '#' in program
  116 | }#include <bits/stdc++.h>
      |  ^
fancyfence.cpp:116:3: error: 'include' does not name a type
  116 | }#include <bits/stdc++.h>
      |   ^~~~~~~
fancyfence.cpp:138:4: error: redefinition of 'long long int t'
  138 | ll t,n;
      |    ^
fancyfence.cpp:23:4: note: 'long long int t' previously declared here
   23 | ll t,n;
      |    ^
fancyfence.cpp:138:6: error: redefinition of 'long long int n'
  138 | ll t,n;
      |      ^
fancyfence.cpp:23:6: note: 'long long int n' previously declared here
   23 | ll t,n;
      |      ^
fancyfence.cpp:139:4: error: redefinition of 'long long int h [100007]'
  139 | ll h[maxn], w[maxn];
      |    ^
fancyfence.cpp:24:4: note: 'long long int h [100007]' previously declared here
   24 | ll h[maxn], w[maxn];
      |    ^
fancyfence.cpp:139:13: error: redefinition of 'long long int w [100007]'
  139 | ll h[maxn], w[maxn];
      |             ^
fancyfence.cpp:24:13: note: 'long long int w [100007]' previously declared here
   24 | ll h[maxn], w[maxn];
      |             ^
fancyfence.cpp:140:11: error: redefinition of 'std::vector<long long int> v'
  140 | vector<ll>v,b;
      |           ^
fancyfence.cpp:25:11: note: 'std::vector<long long int> v' previously declared here
   25 | vector<ll>v,b;
      |           ^
fancyfence.cpp:140:13: error: redefinition of 'std::vector<long long int> b'
  140 | vector<ll>v,b;
      |             ^
fancyfence.cpp:25:13: note: 'std::vector<long long int> b' previously declared here
   25 | vector<ll>v,b;
      |             ^
fancyfence.cpp:142:4: error: redefinition of 'long long int f(long long int)'
  142 | ll f (ll x) {
      |    ^
fancyfence.cpp:27:4: note: 'long long int f(long long int)' previously defined here
   27 | ll f (ll x) {
      |    ^
fancyfence.cpp:146:6: error: redefinition of 'void solve()'
  146 | void solve () {
      |      ^~~~~
fancyfence.cpp:31:6: note: 'void solve()' previously defined here
   31 | void solve () {
      |      ^~~~~
fancyfence.cpp:223:5: error: redefinition of 'int main()'
  223 | int main () {
      |     ^~~~
fancyfence.cpp:108:5: note: 'int main()' previously defined here
  108 | int main () {
      |     ^~~~