[洛谷P5057][CQOI2006]简单题
生活随笔
收集整理的這篇文章主要介紹了
[洛谷P5057][CQOI2006]简单题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目大意:有一個長度為$n$的$01$串,兩個操作:
題解:維護前綴異或和,樹狀數組即可
卡點:無
?
C++ Code:
#include <cstdio> #include <cctype>namespace std {struct istream { #define M (1 << 24 | 3)char buf[M], *ch = buf - 1;inline istream() { #ifndef ONLINE_JUDGEfreopen("input.txt", "r", stdin); #endiffread(buf, 1, M, stdin);}inline istream& operator >> (int &x) {while (isspace(*++ch));for (x = *ch & 15; isdigit(*++ch); ) x = x * 10 + (*ch & 15);return *this;} #undef M} cin;struct ostream { #define M (1 << 24 | 3)char buf[M], *ch = buf - 1;int w;inline ostream& operator << (int x) {if (!x) {*++ch = '0';return *this;}for (w = 1; w <= x; w *= 10);for (w /= 10; w; w /= 10) *++ch = (x / w) ^ 48, x %= w;return *this;}inline ostream& operator << (const char x) {*++ch = x; return *this;}inline ostream& operator << (const char *x) {while (*x) *this << *x++;return *this;}inline ~ostream() { #ifndef ONLINE_JUDGEfreopen("output.txt", "w", stdout); #endiffwrite(buf, 1, ch - buf + 1, stdout);} #undef M} cout; }#define maxn 100010int n, m; namespace BIT {int Tr[maxn], res;inline void add(int p) {for (; p <= n; p += p & -p) Tr[p] ^= 1;}inline int ask(int p) {for (res = 0; p; p &= p - 1) res ^= Tr[p]; return res;} }int main() {std::cin >> n >> m;while (m --> 0) {int op, l, r;std::cin >> op >> l;if (op == 1) {std::cin >> r;BIT::add(l), BIT::add(r + 1);} else std::cout << BIT::ask(l) << '\n';}return 0; }
轉載于:https://www.cnblogs.com/Memory-of-winter/p/10127483.html
總結
以上是生活随笔為你收集整理的[洛谷P5057][CQOI2006]简单题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue-cli watch/timer
- 下一篇: 示例Express中路由规则及获取请求参