답안 #691746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
691746 2023-01-31T13:55:23 Z tolbi Money (IZhO17_money) C++17
0 / 100
1 ms 328 KB
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
#define author tolbi
#include <bits/stdc++.h>
#ifdef LOCAL
	#include "23.h"
#endif
#define int long long
#define endl '\n'
#define vint(x) vector<int> x
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(),x.end())
#define sortrarr(x) sort(x.rbegin(),x.rend())
#define det(x) cout<<"NO\0YES"+x*3<<endl;
#define INF LONG_LONG_MAX
#define rev(x) reverse(x.begin(),x.end());
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tol(bi) (1LL<<((int)(bi)))
const int MOD = 1e9+7;
using namespace std;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
struct SegTree{
	vector<int> segtree;
	SegTree(int n){
		n++;
		segtree.resize(tol(ceil(log2(n)+1))-1,0ll);
	}
	void update(int node){
		node+=segtree.size()/2;
		segtree[node]++;
		while(node){
			node=(node-1)/2;
			segtree[node]++;
		}
	}
	int query(int tarl, int tarr, int l = 0, int r = -1, int node = 0){
		if (r==-1) r = segtree.size()/2;
		if (l>=tarl && r<=tarr) return segtree[node];
		if (r<tarl || l>tarr) return 0;
		int mid = l+(r-l)/2;
		int lnode = query(tarl, tarr, l, mid, node*2+1);
		int rnode = query(tarl, tarr, mid+1, r, node*2+2);
		return lnode+rnode;
	}
};
vector<int> compress(vector<int> arr){
	vector<int> barr = arr;
	map<int,int> mp;
	sortarr(barr);
	int ind = 1;
	for (int i = 0; i < arr.size(); i++){
		if (mp[barr[i]]) continue;
		mp[barr[i]]=ind++;
	}
	for (int i = 0; i < arr.size(); ++i)
	{
		arr[i]=mp[arr[i]];
	}
	return arr;
}
int32_t main(){
	ios;
	int t=1;
	int tno = 0;
	if (!t) cin>>t;
	while (t-(tno++)){
		deci(n);
		vint(arr(n));
		cinarr(arr);
		arr=compress(arr);
		SegTree segtree(n);
		int lind = -1;
		int ans = 0;
		for (int i = 0; i < n; i++){
			if (lind==-1 || lind>arr[i]){
				ans++;
				lind=arr[i];
				segtree.update(arr[i]);
			}
			else {
				if (segtree.query(lind+1,arr[i])==0){
					lind=arr[i];
					segtree.update(arr[i]);
				}
				else {
					lind=arr[i];
					segtree.update(arr[i]);
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
}

Compilation message

money.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      | 
money.cpp: In function 'std::vector<long long int> compress(std::vector<long long int>)':
money.cpp:62: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]
   62 |  for (int i = 0; i < arr.size(); i++){
      |                  ~~^~~~~~~~~~~~
money.cpp:66: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]
   66 |  for (int i = 0; i < arr.size(); ++i)
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -