Submission #479437

# Submission time Handle Problem Language Result Execution time Memory
479437 2021-10-11T20:47:26 Z keta_tsimakuridze Po (COCI21_po) C++17
70 / 70
111 ms 20708 KB
#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

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 time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 5068 KB Output is correct
4 Correct 30 ms 8696 KB Output is correct
5 Correct 44 ms 10424 KB Output is correct
6 Correct 111 ms 15924 KB Output is correct
7 Correct 102 ms 20708 KB Output is correct