日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

[洛谷P5057][CQOI2006]简单题

發(fā)布時(shí)間:2025/6/17 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [洛谷P5057][CQOI2006]简单题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目大意:有一個(gè)長(zhǎng)度為$n$的$01$串,兩個(gè)操作:

  • $1\;l\;r:$把區(qū)間$[l,r]$翻轉(zhuǎn)($0->1,1->0$)
  • $2\;p:$求第$p$位是什么
  • 題解:維護(hù)前綴異或和,樹狀數(shù)組即可

    卡點(diǎn):

    ?

    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; }

      

    轉(zhuǎn)載于:https://www.cnblogs.com/Memory-of-winter/p/10127483.html

    總結(jié)

    以上是生活随笔為你收集整理的[洛谷P5057][CQOI2006]简单题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。