Submission #65507251


Source Code Expand

#include <bits/stdc++.h>

using namespace std;


#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef double db;

const int N = 4e6;

struct Fenwick
{
	int n;
	VL t;
	
	Fenwick(int _n = 0): n(_n), t(n) {}
	
	void upd(int i, LL x)
	{
		for (; i < n; i |= i + 1)
			t[i] += x;
	}
	LL query(int i)
	{
		LL ans = 0;
		for (; i >= 0; i = (i & (i + 1)) - 1)
			ans += t[i];
		return ans;
	}
	int lowerBound(LL x)
	{
		LL sum = 0;
		int i = -1;
		int lg = 31 - __builtin_clz(n);
		while (lg >= 0)
		{
			int j = i + (1 << lg);
			if (j < n && sum + t[j] < x)
			{
				sum += t[j];
				i = j;
			}
			lg--;
		}
		return i + 1;
	}

};

int val[N];


int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	
	Fenwick fn(N);
	FOR (i, 1, N)
	{
		val[i] = 1;
		fn.upd(i, 1);
	}
		
	int q;
	cin >> q;
	set<int> used;
	FOR (i, 0, q)
	{
		int a, b;
		cin >> a >> b;
		if (!used.count(a))
			for (int j = a; j < N; j += a)
			{
				if (val[j])
				{
					fn.upd(j, -1);
					val[j] = 0;
				}
			}
		used.insert(a);
		cout << fn.lowerBound(b) << '\n';		
	}
		
	
	cerr << db(clock()) / CLOCKS_PER_SEC << '\n';
	
	return 0;
}

Submission Info

Submission Time
Task C - Removal of Multiples
User Yarema
Language C++ 23 (gcc 12.2)
Score 600
Code Size 1533 Byte
Status AC
Exec Time 485 ms
Memory 55184 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 1
AC × 40
Set Name Test Cases
Sample 01_sample_01.txt
All 01_sample_01.txt, 02_small_AB_01.txt, 02_small_AB_02.txt, 02_small_AB_03.txt, 02_small_AB_04.txt, 02_small_AB_05.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 05_rand_3_01.txt, 05_rand_3_02.txt, 05_rand_3_03.txt, 05_rand_3_04.txt, 05_rand_3_05.txt, 06_rand_4_01.txt, 06_rand_4_02.txt, 06_rand_4_03.txt, 06_rand_4_04.txt, 06_rand_4_05.txt, 06_rand_4_06.txt, 06_rand_4_07.txt, 06_rand_4_08.txt, 06_rand_4_09.txt, 06_rand_4_10.txt, 06_rand_4_11.txt, 06_rand_4_12.txt, 06_rand_4_13.txt, 06_rand_4_14.txt, 06_rand_4_15.txt, 06_rand_4_16.txt, 07_max_ans_01.txt, 07_max_ans_02.txt, 07_max_ans_03.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 81 ms 49924 KiB
02_small_AB_01.txt AC 211 ms 49924 KiB
02_small_AB_02.txt AC 204 ms 49964 KiB
02_small_AB_03.txt AC 190 ms 50020 KiB
02_small_AB_04.txt AC 198 ms 49876 KiB
02_small_AB_05.txt AC 201 ms 49984 KiB
03_rand_1_01.txt AC 119 ms 55012 KiB
03_rand_1_02.txt AC 120 ms 55008 KiB
03_rand_1_03.txt AC 122 ms 55016 KiB
03_rand_1_04.txt AC 120 ms 55060 KiB
03_rand_1_05.txt AC 120 ms 55092 KiB
04_rand_2_01.txt AC 232 ms 54536 KiB
04_rand_2_02.txt AC 237 ms 54572 KiB
04_rand_2_03.txt AC 220 ms 54524 KiB
04_rand_2_04.txt AC 227 ms 54524 KiB
04_rand_2_05.txt AC 228 ms 54576 KiB
05_rand_3_01.txt AC 134 ms 50012 KiB
05_rand_3_02.txt AC 143 ms 49876 KiB
05_rand_3_03.txt AC 136 ms 49944 KiB
05_rand_3_04.txt AC 137 ms 50076 KiB
05_rand_3_05.txt AC 135 ms 50076 KiB
06_rand_4_01.txt AC 205 ms 54968 KiB
06_rand_4_02.txt AC 230 ms 55136 KiB
06_rand_4_03.txt AC 267 ms 55040 KiB
06_rand_4_04.txt AC 280 ms 55028 KiB
06_rand_4_05.txt AC 276 ms 55060 KiB
06_rand_4_06.txt AC 294 ms 55044 KiB
06_rand_4_07.txt AC 277 ms 55140 KiB
06_rand_4_08.txt AC 296 ms 54972 KiB
06_rand_4_09.txt AC 294 ms 55052 KiB
06_rand_4_10.txt AC 332 ms 55040 KiB
06_rand_4_11.txt AC 391 ms 55056 KiB
06_rand_4_12.txt AC 417 ms 55012 KiB
06_rand_4_13.txt AC 431 ms 55136 KiB
06_rand_4_14.txt AC 469 ms 55024 KiB
06_rand_4_15.txt AC 456 ms 55148 KiB
06_rand_4_16.txt AC 485 ms 55184 KiB
07_max_ans_01.txt AC 191 ms 55048 KiB
07_max_ans_02.txt AC 267 ms 55048 KiB
07_max_ans_03.txt AC 293 ms 54972 KiB