51nod 演算法馬拉松19 A P1674

2021-07-24 05:51:35 字數 1120 閱讀 1669

比賽的時候耗盡千辛萬苦才切出來。。我覺得要切出這道題,肯定要對位運算的性質有些了解。。

因為是and或者or,我們發現,無論是哪個,變化情況種數最多不超過30種,所以總共不超過60種。這也就代表著,在區間裡肯定有一些區間內的答案是一樣的,我們對於這樣的區間,固定左端點,二分右端點。所以時間複雜度是o(60*nlogn)

#include 

#include

#include

#include

using

namespace

std;

const

int n = 1e5+5;

typedef

long

long ll;

const ll mod = 1000000007;

ll dp[n][25][2];

ll a[n];

int bitx[n];

void st(int n)

for(int j = 1; (1

<1

<= n; ++i)

}bitx[1] = 0;

for(int i = 2; i <= n; ++i)

}ll queryand(int l, int r)

ll queryor(int l, int r)

int main(int argc, const

char * argv)

st(n);

ll ans = 0;

for(int i = 1; i <= n; ++i)

l = lastpos, r = n;

while(l <= r)

int pos = min(ansand, ansor);

ans = (ans+(pos-lastpos+1)*lastand%mod*lastor%mod)%mod;

if(pos == n) break;

lastpos = pos+1; lastor = queryor(i, pos+1); lastand = queryand(i, pos+1);}}

printf("%lld\n", ans);

return

0;}

51nod演算法馬拉松32

比賽鏈結 馬拉松是真的難 應該是我太菜了tnt 同bzoj1534 題解戳這裡 n個有標號的點,其中m個是葉子節點。問有多少數的形態。include include include include include using namespace std typedef long long ll co...

51nod演算法馬拉松15

智力徹底沒有了。看來再也拿不到獎金了qaq。a b君的遊戲 因為資料是9b1l,所以我們可以hash試一下資料。include include include include define rep i,s,t for int i s i t i define dwn i,s,t for int i ...

51nod演算法馬拉松13

a 取餘最長路 不難發現路徑可以拆成三條線段,只要知道兩個轉折點的位置就能計算出答案。設sum i,l,r 表示第i行從l到r元素的和,則答案可以表示為sum 1,1,x sum 2,x,y sum 3,y,n p。字首和一下轉化成 s3 n s3 y 1 s2 y s1 x s2 x 1 p,從小...