답안 #364443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364443 2021-02-09T07:40:14 Z Jarif_Rahman Bubble Sort 2 (JOI18_bubblesort2) C++17
0 / 100
9000 ms 1796 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
struct segtree{
	int k;
	vector<ll> sm;
	segtree(int n){
		k = 1;
		while(k <= n) k*=2; k*=2;
		sm.resize(k, 0LL);
	}
	void upd(int in, ll x){
		in+=k/2;
		sm[in] = x, in/=2;
		while(in > 0){
			sm[in] = sm[2*in] + sm[2*in+1];
			in/=2;
		}
	}
	ll get_sum(int l, int r, int nd, int a, int b){
		if(a > r || b < l) return 0LL;
		if(a >= l && b <= r) return sm[nd];
		int md = (a+b)/2;
		return get_sum(l, r, 2*nd, a, md) + get_sum(l, r, 2*nd+1, md+1, b);
	}
	ll sum(int l, int r){
		return get_sum(l, r, 1, 0, k/2-1);
	}
};
vector<int> countScans(vector<int> a, vector<int> in, vector<int> v){
	int n = a.size(), q = v.size();
	vector<int> ans(q);
	for(int k = 0; k < q; k++){
		a[in[k]] = v[k];
		ans[k] = 0;
		segtree seg(n+1);
		vector<pair<int, int>> sth;
		vector<int> prm(n);
		for(int i = 0; i < n; i++) sth.pb({a[i], i});
		sort(sth.begin(), sth.end());
		for(int i = 0; i < n; i++) prm[sth[i].sc] = i;
		for(int i = 0; i < n; i++){
			ans[k]+=seg.sum(prm[i], n);
			seg.upd(prm[i], 1);
		}
	}
	return ans;
}

Compilation message

bubblesort2.cpp: In constructor 'segtree::segtree(int)':
bubblesort2.cpp:14:3: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   14 |   while(k <= n) k*=2; k*=2;
      |   ^~~~~
bubblesort2.cpp:14:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   14 |   while(k <= n) k*=2; k*=2;
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9094 ms 1796 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -