제출 #555159

#제출 시각아이디문제언어결과실행 시간메모리
555159computerboxRadio (COCI22_radio)C++14
10 / 110
1584 ms128864 KiB
/* ID: computerbox --> Huseyn Hajiyev LANG: C++ TASK: target_mode_on */ #include <bits/stdc++.h> //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#define _CRT_SECURE_NO_WARNINGS //#include <boost/multiprecision/cpp_int.hpp> //using boost::multiprecision::cpp_int; #define FAST_READ ios_base::sync_with_stdio(0); #define in freopen("input.txt", "r", stdin); #define out freopen("output.txt", "w", stdout); #define ll long long #define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl; #define deb(x)cout<<"#x = "<<(x)<<endl; #define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define endl "\n" #define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n"; #define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n"; #define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl #define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl; #define MAXN 400010 using namespace std; struct segment { vector<pair<int, int> >primes; }; segment t[4 * 1000010]; int used[1000010]; segment mergee(segment &one, segment &two) { segment three; int l = 0; int r = 0; while(l < (int)one.primes.size() && r < (int)two.primes.size()) { if(one.primes[l].first < two.primes[r].first) { three.primes.pb(one.primes[l]); l++; } else if(one.primes[l].first == two.primes[r].first) { three.primes.pb({one.primes[l].first, one.primes[l].second + two.primes[r].second}); l++; r++; } else { three.primes.pb(two.primes[r]); r++; } } while(l < (int)one.primes.size()) { three.primes.pb(one.primes[l]); l++; } while(r < (int)two.primes.size()) { three.primes.pb(two.primes[r]); r++; } return three; } vector<int>primes; vector<pair<int, int> >primes1[1000010]; segment create(int el) { int ind = 0; segment res; while(el > 1 && ind < (int)primes.size()) { int cnt = 0; while(el % primes[ind] == 0) { cnt++; el /= primes[ind]; } if(cnt)res.primes.pb({primes[ind], 1}); ind++; } if(el > 1) { res.primes.pb({el, 1}); } return res; } void update(int v, int l, int r, int pos) { if(l == r) { if(!t[v].primes.empty()) { t[v].primes.clear(); return ; } segment add = create(pos); for(auto i: add.primes) { t[v].primes.pb(i); } return ; } int mid = l + (r - l) / 2; if(pos <= mid)update(v * 2, l, mid, pos); else update(v * 2 + 1, mid + 1, r, pos); t[v] = mergee(t[v * 2], t[v * 2 + 1]); } segment query(int v, int l, int r, int nac, int konec) { if(l > konec || r < nac) { segment x; return x; } if(l >= nac && r <= konec)return t[v]; int mid = l + (r - l)/ 2; segment one = query(v * 2, l ,mid, nac, konec); segment two = query(v * 2 + 1, mid + 1, r, nac, konec); return mergee(one, two); } int main(){ FAST_READ; cin.tie(0); cout.tie(0); for(int i = 2; i <= 1000000; i++) { if(used[i])continue; for(long long j = i * 1LL * i; j <= 1000000; j += i) { used[j] = 1; } } for(int i = 2; i <= 1000000; i++) { if(!used[i])primes.pb(i); } int n, q; cin >> n >> q; while(q--) { char c; cin >> c; if(c == 'S') { int x; cin >> x; update(1, 1, n, x); } else { int x, y; cin >> x >> y; segment res = query(1, 1, n, x, y); int sig = 0; for(auto i: res.primes) { if(i.second > 1){sig = 1;break;} } if(!sig)cout << "NE" << endl; else cout << "DA" << endl; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...