同一份代码,提交有时AC,有时RE(返回值2147483647) 代码:
#include <bits/stdc++.h>
using namespace std;
#define def auto
#ifdef ONLINE_JUDGE
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1 << 22], *p1(buf), *p2(buf);
#endif
template<typename F>
inline void read(register F&x)
{
x = 0;
short f(1);
register char ch(getchar());
while (ch < '0' || ch > '9')
{
if(ch == '-')
{
f = -1;
}
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x *= f;
}
template<typename F>
inline void write(register F x)
{
if (x < 0)
{
putchar('-'), x = -x;
}
if (x > 9)
{
write(x / 10);
}
putchar(x % 10 + '0');
}
template<typename T,typename... Args>
inline void read(T& t, Args&... args)
{
read(t);
read(args...);
}
struct ODT
{
int l, r;
mutable bool v;
ODT(const int &il, const int &ir, const int &iv):
l(il), r(ir), v(iv)
{
}
inline bool operator<(const ODT&o) const
{
return l < o.l;
}
};
set<ODT> odt;
int n, q, s;
inline def split(register int x)
{
if (x > n)
{
return odt.end();
}
auto it = --odt.upper_bound(ODT(x, 0, 0));
if(it->l == x)
{
return it;
}
int l = it->l, r = it->r, v = it->v;
odt.erase(it);
odt.insert(ODT(l, x - 1, v));
return odt.insert(ODT(x, r, v)).first;
}
inline void assign(int l, int r, int v)
{
auto itr = split(r + 1);
auto itl = split(l);
auto it = itl;
for(; it != itr; ++it)
{
s -= itl->v * (itl->r - itl->l + 1);
}
odt.erase(itl, itr);
odt.insert(ODT(l, r, v));
}
int main()
{
register int l, r, op;
read(n, q);
s = n;
while(q--)
{
read(l, r, op);
if(op == 1)
{
assign(l, r, 0);
}
else
{
assign(l, r, 1);
}
write(s);
}
}