답안 #479276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479276 2021-10-11T06:33:39 Z keta_tsimakuridze Po (COCI21_po) C++14
20 / 70
125 ms 21556 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++) {
		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:26: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]
   26 |   for(int j = 1; j < v[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~
Main.cpp:33: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]
   33 |   for(int j = 0; j < v[i].size(); j++) s.insert(v[i][j]);
      |                  ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Incorrect 3 ms 4940 KB Output isn't correct
3 Incorrect 4 ms 5068 KB Output isn't correct
4 Incorrect 32 ms 8648 KB Output isn't correct
5 Incorrect 50 ms 10620 KB Output isn't correct
6 Correct 116 ms 16884 KB Output is correct
7 Incorrect 125 ms 21556 KB Output isn't correct