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 <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
struct T
{
int i;
int t1;
int t2;
};
signed main()
{
#ifdef ONPC
FILE* stream;
freopen_s(&stream, "input.txt", "r", stdin);
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
int n, q;
string init_config;
cin >> n >> q >> init_config;
assert((int)init_config.size() == n);
for (auto& ch : init_config)
{
assert(ch == '0' || ch == '1');
}
vector<T> v;
vector<int> since(n, 0);
string cur_config = init_config;
vector<vector<int>> ops(q);
for (int iq = 0; iq < q; iq++)
{
string s;
cin >> s;
assert(s == "query" || s == "toggle");
if (s == "query")
{
int l, r;
cin >> l >> r;
l--;
r--;
r--;
assert(0 <= l && l <= r && r < n);
ops[iq] = { l, r };
}
else
{
assert(s == "toggle");
int i;
cin >> i;
i--;
assert(0 <= i && i < n);
cur_config[i] = '0' ^ '1' ^ cur_config[i];
if (cur_config[i] == '1')
{
v.push_back({ i, since[i], iq - 1 + 1 });
}
else
{
since[i] = iq + 1;
}
ops[iq] = { i };
}
}
for (int i = 0; i < n; i++)
{
if (cur_config[i] == '0')
{
v.push_back({ i, since[i], q });
}
}
for (int iq = 0; iq < q; iq++)
{
if ((int)ops[iq].size() == 2)
{
int l = ops[iq][0], r = ops[iq][1];
int sol = 0;
for (int t = 0; t <= iq; t++)
{
bool ok = 1;
for (auto& it : v)
{
if (l <= it.i && it.i <= r)
{
if (it.t1 <= t && t <= it.t2)
{
ok = 0;
}
}
}
sol += ok;
}
cout << sol << "\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |