結果

提出番号 187
提出者 yakimeshi No.2
言語 C++
提出日時 2017-07-08 12:13:43
問題名 (11)いわゆる検索
結果 TLE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 TLE 0% 20001ms 0KB
2 AC 100% 2ms 8336KB
3 TLE 0% 20001ms 0KB
4 TLE 0% 20001ms 0KB
5 TLE 0% 20002ms 0KB
6 TLE 0% 20002ms 0KB
7 TLE 0% 20001ms 0KB
8 TLE 0% 20065ms 0KB
9 TLE 0% 20001ms 0KB
10 TLE 0% 20001ms 0KB
11 TLE 0% 20002ms 0KB
12 TLE 0% 20001ms 0KB
13 TLE 0% 20006ms 0KB
14 TLE 0% 20004ms 0KB
15 TLE 0% 20001ms 0KB
16 TLE 0% 20001ms 0KB
17 TLE 0% 20001ms 0KB
18 TLE 0% 20002ms 0KB
19 TLE 0% 20001ms 0KB
20 TLE 0% 20009ms 0KB

ソースコード

#include <iostream>
using namespace std;

long long n;
long long x;
long long q = 0;
long long A = 0;
long long B[300000];
long long low;
long long high;
long long mid;
long long s = 0;

int main() {

	
	cin >> n;
	for (long long i = 0; i < n; ++i) {
		
		cin >> x;
		B[i] = x;
	}
	
	cin >> q;
	low = 0;
	high = n;
	
	while(s!=q){
		if (A == 0) {	cin >> A;	}
		mid = (low + high) / 2;
		if (B[mid]>A) {
			high = mid;
			continue;
		}

		if (B[n - 1] < A) {
			cout << 0 << endl;
			A = 0;
			++s;
			continue;
		}
		
		if (B[mid] == A) {

			cout << (n - 1) - mid << endl;
			A = 0;
			high = n;
			low = 0;
			++s;
			continue;
		}
		if (B[mid] <A) {
			low=mid;
			continue;
		}

	}
			
	
	return 0;
}