Submission #791370

#TimeUsernameProblemLanguageResultExecution timeMemory
791370AmylopectinFancy Fence (CEOI20_fancyfence)C++14
100 / 100
55 ms9676 KiB
#include <stdio.h> #include <iostream> #include <vector> #include <algorithm> #include <set> #include <stdlib.h> using namespace std; const long long mxn = 1e6 + 10,mo = 1e9 + 7; struct we { long long hhei,idx; }; bool cmp(const struct we &l,const struct we &r) { return l.hhei < r.hhei; } set<long long> see = {}; struct we sot[mxn] = {}; long long hei[mxn] = {},wei[mxn] = {},chei[mxn] = {},enn[mxn] = {}; long long pot(long long l) { long long cn = (l * (l+1)) / 2; return cn % mo; } int main() { // freopen("input1.txt","r",stdin); long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen; set<long long> :: iterator f; scanf("%lld",&n); for(i=0; i<n; i++) { scanf("%lld",&hei[i]); sot[i] = {hei[i],i}; } for(i=1; i<=n; i++) { scanf("%lld",&wei[i]); wei[i] += wei[i-1]; } sort(sot,sot+n,cmp); see.insert(0); chei[0] = 0; enn[0] = n-1; su = 0; for(i=0; i<n; i++) { cn = sot[i].idx; f = see.upper_bound(cn); cl = (*(prev(f))); cen = enn[cl]; fn = pot((wei[cen+1] - wei[cl])%mo); fm = (pot(hei[cn]) - pot(chei[cl])); if(fm < 0) { fm += mo; } su += (fn * fm) % mo; su %= mo; if(cn > cl) { chei[cl] = hei[cn]; enn[cl] = cn-1; } if(cen > cn) { see.insert(cn+1); chei[cn+1] = hei[cn]; enn[cn+1] = cen; } } printf("%lld\n",su); return 0; }

Compilation message (stderr)

fancyfence.cpp: In function 'int main()':
fancyfence.cpp:28:17: warning: unused variable 'j' [-Wunused-variable]
   28 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
      |                 ^
fancyfence.cpp:28:21: warning: unused variable 'm' [-Wunused-variable]
   28 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
      |                     ^
fancyfence.cpp:28:26: warning: unused variable 'cm' [-Wunused-variable]
   28 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
      |                          ^~
fancyfence.cpp:28:38: warning: unused variable 'cr' [-Wunused-variable]
   28 |     long long i,j,n,m,cn,cm,fn,fm,cl,cr,su,cen;
      |                                      ^~
fancyfence.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
fancyfence.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         scanf("%lld",&hei[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
fancyfence.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%lld",&wei[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
#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...