This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
struct IT
{
int n;
vector<int> st;
IT(int _n)
{
n = _n;
st.resize(n*4+1, 0);
}
void build(int id, int l, int r, int pos, int x)
{
if(l == r)
{
st[id] = x;
return;
}
int mid = (l+r)>>1;
if(pos <= mid)build(id<<1, l, mid, pos, x);
else build(id<<1|1, mid+1, r, pos, x);
st[id] = max(st[id<<1], st[id<<1|1]);
}
void build(int pos, int x)
{
build(1, 1, n, pos, x);
}
int get(int id, int l, int r, int u, int v)
{
if(u <= l && r <= v)return st[id];
if(u > r || l > v)return 0;
int mid = (l+r)>>1;
return max(get(id<<1, l, mid, u, v), get(id<<1|1, mid+1, r, u, v));
}
int get(int l, int r)
{
return get(1, 1, n, l, r);
}
};
int main()
{
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<int> a, on;
a.resize(n+1, 0);
on.resize(n+1, 0);
for(int i = 2; i <= n; i ++)
{
//cout << a[i] <<" ";
for(int j = 2; j <= n/i; j ++)
a[i*j] = max(a[i*j], (j-1)*i);
}
IT it(n);
while(m -- > 0)
{
char c;
cin >> c;
if(c == 'S')
{
int pos;
cin >> pos;
on[pos] ^= 1;
if(on[pos])
{
it.build(pos, a[pos]);
}
else
{
it.build(pos, 0);
}
}
else
{
int l, r;
cin >> l >> r;
if(it.get(l, r) >= l)cout << "DA\n";
else cout << "NE\n";
}
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |