Submission #479437

#TimeUsernameProblemLanguageResultExecution timeMemory
479437keta_tsimakuridzePo (COCI21_po)C++17
70 / 70
111 ms20708 KiB
#include<bits/stdc++.h> #define f first #define s second #define int long long #define pii pair<int,int> using namespace std; const int N = 2e5 + 5, mod = 1e9 + 7; // ! int t,n,a[N]; map<int,int> id; set<int> s; vector<int> x, v[N]; main(){ cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; x.push_back(a[i]); } sort(x.begin(),x.end()); int ans = 0, idx = 0; for(int i = 0; i < n; i++) { if(!i || x[i] != x[i - 1]) idx++; id[x[i]] = idx; } for(int i = 1; i <= n; i++) v[id[a[i]]].push_back(i); for(int i = 1; i <= idx; i++) { if(!(i == 1 && !x[0])) { for(int j = 1; j < v[i].size(); j++) { int prev = v[i][j - 1], cur = v[i][j]; if(s.upper_bound(prev) != s.end()) { if(*s.upper_bound(prev) < cur) ans++; } } ans++; } for(int j = 0; j < v[i].size(); j++) s.insert(v[i][j]); } cout << ans; }

Compilation message (stderr)

Main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main(){
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:27:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |    for(int j = 1; j < v[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~
Main.cpp:35:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int j = 0; j < v[i].size(); j++) s.insert(v[i][j]);
      |                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...