Submission #329142

#TimeUsernameProblemLanguageResultExecution timeMemory
329142M_WMountains (NOI20_mountains)C++14
64 / 100
2095 ms10064 KiB
#include <bits/stdc++.h> using namespace std; long long h[300300]; vector<long long> v; int main(){ int N; vector<long long> cnt; scanf("%d", &N); for(int i = 0; i < N; i++){ scanf("%lld", &h[i]); if(i == 0){ v.push_back(h[i]); cnt.push_back(0); continue; } auto it = upper_bound(v.begin(), v.end(), h[i]); v.insert(it, h[i]); cnt.push_back(lower_bound(v.begin(), v.end(), h[i]) - v.begin()); } v.clear(); long long sum = 0; for(int i = N - 1; i >= 0; i--){ if(i == 0){ v.push_back(h[i]); cnt.push_back(0); continue; } auto it = upper_bound(v.begin(), v.end(), h[i]); v.insert(it, h[i]); sum += cnt[i] * 1ll * (lower_bound(v.begin(), v.end(), h[i]) - v.begin()) * 1ll; } printf("%lld", sum); }

Compilation message (stderr)

Mountains.cpp: In function 'int main()':
Mountains.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Mountains.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |   scanf("%lld", &h[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...