2018/7/27 補了一點線段樹、hack it QAQ...
阿新 • • 發佈:2018-07-28
lap rst for 離散化 direct begin ons tdi opened
https://blog.csdn.net/yanhu6955/article/details/81217308
為什麽是素數:https://blog.csdn.net/qq_41608020/article/details/81213481
https://www.cnblogs.com/tiberius/p/9375743.html
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int p = 47; 5 const int N = p * p; 6 int ans[N + 5][N + 5]; 7 8 int main(){9 puts("2000"); 10 ///(p*p) * (p*p) -> 0...p*p - 1 row(x) + (0...p-1),(p...2p-1),... group(k = x / p) , row -> i = 0...p-1 team(i). 11 for(int x = 0; x < N; x++){///row 12 int k = x / p;///k*i(offset->last row) 0...p-1|0, p...2p-1|2, 2p...3p-1|2, ...|(k=x/p). 13 int b = x % p;14 for(int i = 0; i < p; i++){ 15 int y = i * p ///inline offset. 16 + (k * i + b) % p; 17 ans[x][y] = 1; 18 } 19 } 20 for(int i = 0; i < 2000; i++){ 21 for(int j = 0; j < 2000; j++) 22 printf("%d", ans[i][j]); 23 puts(""); 24 } 25 return 0; 26 }
1 ///4 ways to solve inv pair. 2 ///https://blog.csdn.net/haolexiao/article/details/54989306 3 4 #include <bits/stdc++.h> 5 using namespace std; 6 7 const int N = 1e5 + 5; 8 int num[N]; 9 long long cnt; 10 int temp[N];/// 11 void Merge(int left, int mid, int right) 12 { 13 ///int temp[N];///TLE 14 int i = left, j = mid + 1, k = left; 15 while(i <= mid&&j <= right) 16 { 17 if (num[i] > num[j]) 18 { 19 cnt += mid - i + 1; 20 temp[k++] = num[j++]; 21 } 22 else 23 temp[k++] = num[i++]; 24 } 25 while (i <= mid) temp[k++] = num[i++]; 26 while (j <= right) temp[k++] = num[j++]; 27 for (i = left; i <= right; i++) 28 num[i] = temp[i]; 29 } 30 31 void mergeSort(int left, int right) 32 { 33 if (left < right) 34 { 35 int mid = (left + right) / 2; 36 mergeSort(left, mid); 37 mergeSort(mid + 1, right); 38 Merge(left, mid, right); 39 } 40 } 41 42 int main() 43 { 44 int n, x, y; 45 while(~scanf("%d%d%d",&n, &x, &y)) 46 { 47 for(int j = 0; j < n; j++) 48 scanf("%d", &num[j]); 49 cnt = 0; 50 mergeSort(0, n-1);/// 51 long long ans=cnt*min(x,y); 52 printf("%lld\n", ans); 53 } 54 return 0; 55 56 } 57 /*#include<bits/stdc++.h> 58 using namespace std; 59 typedef long long ll; 60 ll x,y,n; 61 const int maxn= 500005; 62 ll aa[maxn];//離散化後的數組 63 ll c[maxn]; //樹狀數組 64 65 struct Node 66 { 67 int v; 68 int order; 69 }a[maxn]; 70 71 bool cmp(Node a, Node b) 72 { 73 if(a.v == b.v) return a.order < b.order; 74 ///if a.v == b.v, the order shouldn‘t be changed.WAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaa!!!!!!!!!!! 75 ///or 76 return a.v < b.v; 77 } 78 79 int lowbit(int k) 80 { 81 return k&(-k); 82 } 83 84 void update(int t, int value) 85 { 86 int i; 87 for (i = t; i <= n; i += lowbit(i)) 88 c[i] += value; 89 } 90 91 int getsum(int t) 92 { 93 int i, sum = 0; 94 for (i = t; i >= 1; i -= lowbit(i)) 95 sum += c[i]; 96 return sum; 97 } 98 99 int main() 100 { 101 int i; 102 while (scanf("%lld%lld%lld",&n,&x,&y)!=EOF) 103 { 104 for (i = 1; i <= n; i++) 105 { 106 scanf("%d", &a[i].v); 107 a[i].order = i; 108 } 109 sort(a + 1, a + n + 1,cmp); 110 memset(c, 0, sizeof(c)); 111 for (i = 1; i <= n; i++) 112 aa[a[i].order] = i; 113 ///right position.(make the same number‘s aa equal or if(a.v == b.v) return a.order < b.order;(cmp) ). 114 ll ans = 0; 115 for (i = 1; i <= n; i++) 116 { 117 update(aa[i], 1); 118 ans += i - getsum(aa[i]);/// 119 } 120 printf("%lld\n",min(x, y)*ans); 121 } 122 return 0; 123 } 124 125 */ 126 /* 127 #include <iostream> 128 #include <stdio.h> 129 #include <math.h> 130 #include <string.h> 131 #include <time.h> 132 #include <stdlib.h> 133 #include <string> 134 #include <bitset> 135 #include <vector> 136 #include <set> 137 #include <map> 138 #include <queue> 139 #include <algorithm> 140 #include <sstream> 141 #include <stack> 142 #include <iomanip> 143 using namespace std; 144 #define pb push_back 145 #define mp make_pair 146 typedef pair<int,int> pii; 147 typedef long long ll; 148 typedef double ld; 149 typedef vector<int> vi; 150 #define fi first 151 #define se second 152 #define fe first 153 #define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);} 154 #define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);} 155 #define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);} 156 #define es(x,e) (int e=fst[x];e;e=nxt[e]) 157 #define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e]) 158 #define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");} 159 #define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");} 160 #define SZ 666666 161 //orz kczno1 POD only 162 template<typename T> 163 struct vec{T *a;int n;void clear(){n=0;} 164 void pb(const T &x){if((n&-n)==n)a=(T*)realloc(a,(n*2)*sizeof(T));a[n++]=x;} 165 inline T* begin(){return a;}inline T* end() {return a+n;}}; 166 int n,x,y,a[SZ],g[SZ],bs[SZ]; 167 void sol() 168 { 169 for(int i=1;i<=n;++i) bs[i]=0;/// 170 for(int i=1;i<=n;++i) 171 scanf("%d",a+i),g[i]=a[i]; 172 sort(g+1,g+1+n); 173 for(int i=1;i<=n;++i) 174 a[i]=n+1-(lower_bound(g+1,g+1+n,a[i])-g);///the amount of a[j] | a[j]>=a[i]; 175 ///lower_bound!!!(better than sort + struct) 176 //bool cmp(Node a, Node b){ 177 //if(a.v == b.v) return a.order < b.order;///if a.v == b.v, the order shouldn‘t be changed.WAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaa!!!!!!!!!!! 178 //return a.v < b.v; 179 //} 180 ll inv=0; 181 for(int i=1;i<=n;++i) 182 { 183 for(int g=a[i]-1;g>=1;g-=g&-g) inv+=bs[g];///{1...cnt(>)} direct child 184 for(int g=a[i];g<=n;g+=g&-g) ++bs[g];///{cnt(>=a[i])...n} -> g is the direct inv(parent)(who should be smaller than "a[i]"); 185 } 186 printf("%lld\n",min(x,y)*inv); 187 } 188 int main() 189 { 190 while(scanf("%d%d%d",&n,&x,&y)!=EOF) sol(); 191 } 192 193 */論逆序數的四種求法以及如何把歸並排序寫挫。。。
HDU 6315
http://www.cnblogs.com/tiberius/p/9369683.html
超棒的思路:維護區間最小值min,以此為標準修改lazy標記,減少更新次數。理不好思路套板子分分鐘tle而理直氣壯.jpg...q^q...
2018/7/27 補了一點線段樹、hack it QAQ...