Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///D
- #include<bits/stdc++.h>
- using namespace std;
- #define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
- #define read freopen("cases.in","r",stdin)
- #define write freopen("output.txt","w",stdout)
- #define D(x) cout << '>' << #x << ':' << x << endl
- #define rep(i,k,n) for(int i=k;i<n;i++)
- #define ll long long int
- #define ull unsigned long long int
- #define UI unsigned int
- #define LD long double
- #define VI vector<int>
- #define VLL vector<ll>
- #define VB vector<bool>
- #define VLD vector<LD>
- #define VULL vector<ull>
- #define VVI vector<VI>
- #define PII pair<int, int>
- #define MP(x, y) make_pair(x, y)
- #define PB(x) push_back(x)
- #define ALL(p) p.begin(),p.end()
- #define CLR(p) memset(p, 0, sizeof(p))
- #define MEM(a, b) memset(a, (b), sizeof(a))
- #define ff first
- #define ss second
- inline void sc(int &a) { scanf("%d", &a); }
- inline void sc(ll &a) { scanf("%lld", &a); }
- inline void sc(ull &a) { scanf("%llu", &a); }
- inline void sc(char *a) { scanf("%s", a); }
- inline void sc(LD &a) { cin >> a; }
- inline void sc(string &a) { cin >> a; }
- inline void sc(double &a) { cin >> a; }
- inline void sc(bool &a) { int aa; sc(aa); a = aa; }
- template<typename T1, typename T2> inline void sc(pair<T1, T2> &a) { sc(a.ff); sc(a.ss); }
- template<typename T> inline void sc(vector<T> &a) { for (T &aa : a) sc(aa); }
- template<typename T, typename... Args> inline void sc(T &a, Args &... args) { sc(a); sc(args...); }
- inline void print(const int &a) { printf("%d", a); }
- inline void print(const ll &a) { printf("%lld", a); }
- inline void print(const ull &a) { printf("%llu", a); }
- inline void print(const char *a) { printf("%s", a); }
- inline void print(const char &a) { printf("%c", a); }
- inline void print(const string &a) { for (const char &aa : a) print(aa); }
- inline void print(const bool &a) { printf("%d", a); }
- template<typename T1, typename T2> inline void print(const pair<T1, T2> &a) { print("{"); print(a.ff); print(", "); print(a.ss); print("}"); }
- template<typename T> inline void print(const T &a) { int i = 0; print("{"); for (const auto &aa : a) { if (i++) print(", "); print(aa); } print("}"); }
- template<typename T, typename... Args> inline void print(const T &a, const Args &... args) { print(a); print(" "); print(args...); }
- template<typename... Args> inline void O(const Args &... args) { print(args...); print("\n"); }
- template < typename T > inline T power(T p, T e, T M){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; }
- template < typename T > inline T power(T p, T e){ T ret = 1; for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p); p = (p * p); } return (T)ret; }
- #ifndef ONLINE_JUDGE
- #define debug(args...) { string _s = "[" + string(#args) + "] = ["; print(_s); deb(args); }
- void deb() {}
- template<typename T, typename... Args>
- void deb(T a, Args... args) {
- print(a), print((sizeof...(args) ? ", " : "]\n"));
- deb(args...);
- }
- #else
- #define debug(args...)
- #endif
- const double PI = acos(-1.0);
- const double EPS = 1e-9;
- const int MOD = 1e9+7;
- const int MAXN = 1e6+7;
- #define int ll
- int mark[MAXN], odd_prefix[5007];
- signed main() {
- #ifndef ONLINE_JUDGE
- write;
- #endif
- read;
- int t;
- sc(t);
- while(t--)
- {
- // MEM(mark, 0);
- // MEM(odd_prefix, 0);
- int n;
- sc(n);
- VI vv(n);
- for (int i = 0; i < n; i++)
- {
- sc(vv[i]);
- // mark[vv[i]]++;
- // if(mark[vv[i]] % 2 == 0)
- // odd_prefix[i + 1] = odd_prefix[i] - 1;
- // else
- // odd_prefix[i + 1] = odd_prefix[i] + 1;
- }
- int cnt = 0;
- for (int i = 0; i < n; i++)
- {
- // int mark[MAXN] = {0};
- // mark[vv[i]]++;
- // MEM(mark, 0);
- // map<int, int> mark;
- int odd = 0;
- for (int j = i; j < n; j++)
- {
- mark[vv[j]]++;
- if(mark[vv[j]] %2 == 0)
- odd--;
- else
- odd++;
- if(odd == 1) cnt++;
- // debug(i, j, cnt);
- }
- for (int j = i; j < n; j++) mark[vv[j]] = 0;
- }
- O(cnt);
- }
- }
- ///M
- #include<bits/stdc++.h>
- using namespace std;
- #define rep(i,k,n) for(int i=k;i<n;i++)
- #define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
- #define read freopen("chess.in","r",stdin)
- #define write freopen("output.txt","w",stdout)
- #define D(x) cout << '>' << #x << ':' << x << endl
- #define DD(x,y) cout << '>' << #x << ':' << x << ' ' << #y << ':' << y << endl
- #define DDD(x,y,z) cout << '>' << #x << ':' << x << ' ' << #y << ':' << y << ' ' << #z << ':' << z << endl
- #define PI acos(-1)
- #define MP(x, y) make_pair(x, y)
- #define PB(x) push_back(x)
- #define ALL(p) p.begin(),p.end()
- #define CLR(p) memset(p, 0, sizeof(p))
- #define MEM(a, b) memset(a, (b), sizeof(a))
- #define ff first
- #define ss second
- #define sf scanf
- #define pf printf
- #define PII pair<int, int>
- #define ll long long int
- #define ull unsigned long long int
- inline int two(int n) { return 1 << n; }
- inline int test(int n, int b) { return (n>>b)&1; }
- inline void set_bit(int & n, int b) { n |= two(b); }
- inline void unset_bit(int & n, int b) { n &= ~two(b); }
- inline int last_bit(int n) { return n & (-n); }
- inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
- template < class T > inline T gcd(T a, T b) {while(b) { a %= b; swap(a, b); } return a;}
- template < class T > inline T bigmod(T p, T e, T M){
- ll ret = 1;
- for(; e > 0; e >>= 1){ if(e & 1) ret = (ret * p) % M; p = (p * p) % M; }
- return (T)ret;
- }
- template < class T > inline T power(T a, T n) {
- if(n==0) return 1;
- if(n==1) return a;
- T R = power(a,n/2);
- return (n%2==0) ? R*R : R*a*R;
- }
- int fx4[] = {0, 0, -1, +1};
- int fy4[] = {+1, -1, 0, 0};
- int fx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
- int fy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
- int fx8Knight[] = {+2, +2, +1, -1, -2, -2, -1, +1};
- int fy8Knight[] = {+1, -1, -2, -2, -1, +1, +2, +2};
- const int MAXN = 1e5 + 3;
- #define int ll
- signed main()
- {
- // #ifndef ONLINE_JUDGE
- // write;
- read;
- // #endif
- //fast;
- int t;
- cin >> t;
- while(t--){
- int n,k;
- cin>>n>>k;
- int a = n-1 - (k+1)+1;
- int lim = (n-1)/(k+1);
- int sum = lim*(2*a+(lim-1)*(-k-1));
- sum/=2;
- sum*=2;
- sum+=(n-1);
- int tot = n*n - sum;
- cout<<tot-1<<endl;
- }
- return 0;
- }
- ///G
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace __gnu_pbds;
- using namespace std;
- #define int long long
- #define unt unsigned int
- #define LD long double
- #define nl "\n"
- #define nspace(s) for(int i=0;i<s;i++)cout<<" ";
- #define wat1(s,x) nspace(s) ; cout << #x << " is " << x << nl;
- #define wat2(s,x,y) nspace(s) ; cout << #x << " is " << x << " " << #y << " is " << y << nl ;
- #define wat3(s,x,y,z) nspace(s) ; cout << #x << " is " << x << " " << #y << " is " << y << " "<< #z << " is " << z << nl;
- #define wat4(s,x,y,z,a) nspace(s) ; cout << #x << " is " << x << " " << #y << " is " << y << " "<< #z << " is " << z << " " << #a << " is " << a << nl;
- #define wat5(s,x,y,z,a,b) nspace(s) ; cout << #x << " is " << x << " " << #y << " is " << y << " "<< #z << " is " << z << " " << #a << " is " << a << " " << #b << " is " << b << nl;
- #define line cout<<"\n";
- #define gap cout<<" ";
- #define pii pair<int, int>
- #define vpi vector<pii>
- #define vii vector<int>
- #define vsi vector<string>
- #define umap unordered_map
- #define pqueue priority_queue
- #define mip make_pair
- #define pb push_back
- #define ppb pop_back
- #define pf push_front
- #define ppf pop_front
- #define ff first
- #define ss second
- #define all(x) x.begin(), x.end()
- #define vlb(x, y) lower_bound(all(x), y)-x.begin()
- #define vub(x, y) upper_bound(all(x), y)-x.begin()
- #define takes(a,n,type) type *a=new type[n+10];
- #define mem(a,x) memset(a, x, sizeof(a))
- #define sp(x) setprecision(x) << fixed
- #define PI acos(-1.0)
- #define eps 1e-12
- #define read freopen("wifi.in","r",stdin)
- #define write freopen("output.txt","w",stdout)
- #define file_io read;write
- #define fast_io ios_base::sync_with_stdio(0);cin.tie(0)
- #define fbo find_by_order
- #define ofk order_of_key
- inline int sci() {int a;scanf("%lld",&a);return a;}
- inline char scc() {char a;scanf("%c",&a);return a;}
- inline double scd() {double a;scanf("%lf",&a);return a;}
- const int big = INT_MAX;
- const int sml = INT_MIN;
- const int mod = 100000007;
- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
- int x4[] = {1, 0, -1, 0};
- int y4[] = {0, 1, 0, -1};
- int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};
- int y8[] = { 0, 1, 0, -1, 1, -1, -1, 1};
- int kx[] = {2, -2, 2, -2, 1, -1, 1, -1};
- int ky[] = { -1, 1, 1, -1, 2, -2, -2, 2};
- inline bool valid(int x, int y, int rs, int cs, int r, int c) {return ((x >= rs && x <= r) && (y >= cs && y <= c));}
- inline int two(int n) { return 1LL << n; }
- inline int db2(int n) { return !(n & 1LL); }
- inline bool ispof2 (int x) {return x && (!(x & (x - 1)));}
- inline int check(int n, int b) { return (n >> b) & 1LL; }
- inline void biton(int & n, int b) { n |= two(b); }
- inline void bitoff(int & n, int b) { n &= ~two(b); }
- inline int ones(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; }
- int mpow(int x, int y, int p)
- {
- int res = 1;
- x = x % p;
- if (x == 0) return 0;
- while (y > 0)
- {
- if (y & 1) res = (res * x) % p;
- y = y >> 1;
- x = (x * x) % p;
- }
- return res;
- }
- void fileoj()
- {
- #ifndef ONLINE_JUDGE
- file_io;
- #endif
- }
- int pre[1000000][30];
- int ok(vii &v,int val,int mid)
- {
- for(int i=0;i<=v.size()-mid;i++)
- {
- int r = 0;
- if(i==0)
- {
- for(int j = 21;j>=0;j--)
- {
- if(pre[i+mid-1][j])biton(r,j);
- }
- if(r<=val)return r;
- continue;
- }
- for(int j = 21;j>=0;j--)
- {
- if(pre[i+mid-1][j]-pre[i-1][j])biton(r,j);
- }
- if(r<=val)return r;
- }
- return 0;
- }
- int bs(vii &v,int val)
- {
- int lo = 1;
- int hi = v.size()+1;
- int ans = 0;
- while(lo<hi)
- {
- int mid = (lo+hi)/2;
- int okz = ok(v,val,mid);
- //wat2(4,okz,mid);
- if(okz)
- {
- lo = mid+1;
- ans = mid;
- }
- else
- {
- hi = mid;
- }
- }
- return ans;
- }
- int32_t main()
- {
- read;
- int t=1;
- cin>>t;
- for(int tc=1;tc<=t;tc++)
- {
- int n,v;
- cin>>n>>v;
- vii vc;
- for(int i=0;i<n;i++)
- {
- int a;
- cin>>a;
- vc.pb(a);
- for(int j=21;j>=0;j--)
- {
- pre[i][j]+=check(a,j);
- }
- }
- for(int i=1;i<n;i++)
- {
- for(int j=21;j>=0;j--)
- {
- pre[i][j]=pre[i][j]+pre[i-1][j];
- }
- }
- int ans = bs(vc,v);
- for(int i=0;i<n;i++)
- {
- for(int j=21;j>=0;j--)
- {
- pre[i][j]=0;
- }
- }
- cout<<ans<<nl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement