Submission #555105

# Submission time Handle Problem Language Result Execution time Memory
555105 2022-04-30T07:29:36 Z fuad27 Radio (COCI22_radio) C++17
30 / 110
780 ms 9592 KB
#include<bits/stdc++.h>
using namespace std;
template<typename T>
auto operator<<(ostream &os, T&v)->decltype(v.begin(), os){
	os << "[";
	int f = 0;
	for(auto i:v) {
		if(f++)os << ", ";
		os << i;
	}
	os << "]";
	return os;
}
template<typename F, typename S>
ostream& operator<<(ostream &os, pair<F, S> const &p) {
	return os << "(" << p.first << ", " << p.second << ")";
}
ostream& operator<<(ostream &os, string& s) {
	for(char i:s){
		os << i;
	}
	return os;
}
void debug(){}
template<typename T, typename... V>
void debug(T t, V... v) {
	cerr << t;
	if(sizeof...(v)) {
		cerr << ", "; debug(v...);
	}
}
#ifdef LOCAL
#define dbg(x...) cerr << "[" << #x << "]: " << "["; debug(x); cerr << "]\n";
#else
#define dbg(x...)
#endif


int main () {
	int n, q;
	cin >> n >> q;
	if(0) {
//	if(n <= 100 and q <= 200) {
		vector<int> v(n+1);
		while(q--) {
			char c;
			cin >> c;
			if(c == 'S') {
				long long in;
				cin >> in;
				v[in] ^= 1;
			}
			else if(c == 'C') {
				long long l, r;
				cin >> l >> r;
				bool check = false;
				for(int i =l;i<=r;i++) {
					for(int j = l;j<=r;j++) {
						if(j == i)continue;
						if(!v[j] or !v[i])continue;
						if(__gcd(i, j)!=1) {
							check = true;
						}
					}
				}
				cout << (check?"DA":"NE") << "\n";
			}
		}
	}
	else {
		vector<bool> used(n+1);
		vector<long long> cnt(n+1);
		long long c = 0;
		while(q--) {
			char ch;
			cin >> ch;
			if(ch == 'S') {
				long long in;
				cin >> in;
				if(!used[in]) {
					used[in] = true;
					cnt[in]++;
					if(cnt[in] == 2)c++;
					for(int i = 2;i*i<=in;i++) {
						if(in%i == 0) {
							cnt[i]++;
							if(cnt[i] == 2)c++;
							if(in/i!=i)  {
								cnt[in/i]++;
								if(cnt[in/i] == 2)c++;
							}
						}
					}
				}
				else {
					used[in] = false;
					cnt[in]--;
					if(cnt[in] == 1)c--;
					for(int i = 2;i*i<=in;i++) {
						if(in%i == 0) {
							cnt[i]--;
							if(cnt[i] == 1)c--;
							if(in/i!=i)  {
								cnt[in/i]--;
								if(cnt[in/i] == 1)c--;
							}
						}
					}
				}
				dbg(cnt);
			}
			else {
				long long l, r;
				cin >> l >> r;
				cout << (c?"DA":"NE") << "\n";
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 218 ms 1112 KB Output is correct
2 Correct 542 ms 5656 KB Output is correct
3 Correct 780 ms 9592 KB Output is correct
4 Correct 35 ms 1256 KB Output is correct
5 Correct 296 ms 4940 KB Output is correct
6 Correct 761 ms 9524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -