标签:ret uil swap pen stdout += for int UI
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<cctype> 5 #include<cmath> 6 #include<map> 7 #include<iostream> 8 using namespace std; 9 typedef long long ll; 10 #define enter printf("\n") 11 const int INF = 0x3f3f3f3f; 12 const int maxn = 1e5 + 5; 13 inline ll read() 14 { 15 ll ans = 0; 16 char ch = getchar(), last = ‘ ‘; 17 while(!isdigit(ch)) {last = ch; ch = getchar();} 18 while(isdigit(ch)) 19 { 20 ans = ans * 10 + ch - ‘0‘; ch = getchar(); 21 } 22 if(last == ‘-‘) ans = -ans; 23 return ans; 24 } 25 26 map<ll, int> mp; 27 int n, m, cnt = 0; 28 struct Node 29 { 30 ll x, y; 31 }a[maxn]; 32 int t[maxn], pos = 0; 33 34 int l[maxn << 2], r[maxn << 2], Max[maxn << 2], lazy[maxn << 2]; 35 void build(int L, int R, int now) 36 { 37 l[now] = L; r[now] = R; 38 if(L == R) {Max[now] = 0; return;} 39 int mid = (L + R) >> 1; 40 build(L, mid, now << 1); 41 build(mid + 1, R, now << 1 | 1); 42 } 43 void pushdown(int now) 44 { 45 if(lazy[now]) 46 { 47 // Max[now] = max(Max[now << 1], Max[now << 1 | 1]); 48 Max[now] += lazy[now]; 49 lazy[now << 1] += lazy[now]; 50 lazy[now << 1 | 1] += lazy[now]; 51 lazy[now] = 0; 52 } 53 } 54 void update(int L, int R, int now, int d) 55 { 56 pushdown(now); 57 if(L == l[now] && R == r[now]) 58 { 59 Max[now]++; 60 lazy[now << 1] += d; 61 lazy[now << 1 | 1] +=d; 62 // lazy[now] += d; 63 return; 64 } 65 // pushdown(now); 66 int mid = (l[now] + r[now]) >> 1; 67 if(R <= mid) update(L, R, now << 1, 1); 68 else if(L > mid) update(L, R, now << 1 | 1, 1); 69 else {update(L, mid, now << 1, 1); update(mid + 1, R, now << 1 | 1, 1);} 70 Max[now] = max(Max[now << 1], Max[now << 1 | 1]); 71 } 72 ll query(int L, int R, int now) 73 { 74 if(L == l[now] && R == r[now]) return Max[now]; 75 pushdown(now); 76 int mid = (l[now] + r[now]) >> 1; 77 if(R <= mid) return query(L, R, now << 1); 78 else if(L > mid) return query(L, R, now << 1 | 1); 79 else return max(query(L, mid, now << 1), query(mid + 1, R, now << 1 | 1)); 80 Max[now] = max(Max[now << 1], Max[now << 1 | 1]); 81 } 82 83 int main() 84 { 85 freopen("aotusi.in", "r", stdin); 86 freopen("aotusi.out", "w", stdout); 87 n = read(); m = read(); 88 mp.clear(); 89 for(int i = 1; i <= m; ++i) 90 { 91 a[i].x = read(); a[i].y = read(); 92 ll tpa = a[i].x, tpb = a[i].y; 93 // if(!mp[tpa]) {mp[tpa] = ++cnt;} 94 // if(!mp[tpb]) {mp[tpb] = ++cnt;} 95 t[++pos] = a[i].x; t[++pos] = a[i].y; 96 } 97 sort(t + 1, t + pos + 1); 98 for(int i = 1; i <= pos; ++i) if(!mp[t[i]]) mp[t[i]] = ++cnt; 99 build(1, cnt, 1); 100 for(int i = 1; i <= m; ++i) 101 { 102 int tpa = mp[a[i].x], tpb = mp[a[i].y]; 103 // printf("%d %d\n", tpa, tpb); 104 // if(tpa > tpb) swap(tpa, tpb); 105 update(tpa, tpb, 1, 1); 106 } 107 // printf("%lld\n", query(1, cnt, 1)); 108 printf("%d\n", Max[1]); 109 return 0; 110 }
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<cctype> 5 #include<cmath> 6 #include<map> 7 #include<iostream> 8 using namespace std; 9 typedef long long ll; 10 #define enter printf("\n") 11 const int INF = 0x3f3f3f3f; 12 const int maxn = 1e5 + 5; 13 inline ll read() 14 { 15 ll ans = 0; 16 char ch = getchar(), last = ‘ ‘; 17 while(!isdigit(ch)) {last = ch; ch = getchar();} 18 while(isdigit(ch)) 19 { 20 ans = ans * 10 + ch - ‘0‘; ch = getchar(); 21 } 22 if(last == ‘-‘) ans = -ans; 23 return ans; 24 } 25 26 map<ll, int> mp; 27 int n, m, cnt = 0; 28 struct Node 29 { 30 ll x, y; 31 }a[maxn]; 32 int t[maxn << 1], pos = 0; 33 34 //int l[maxn << 2], r[maxn << 2], Max[maxn << 2], lazy[maxn << 2]; 35 int l[maxn << 3], r[maxn << 3], Max[maxn << 3], lazy[maxn << 3]; 36 void build(int L, int R, int now) 37 { 38 l[now] = L; r[now] = R; 39 if(L == R) {Max[now] = 0; return;} 40 int mid = (L + R) >> 1; 41 build(L, mid, now << 1); 42 build(mid + 1, R, now << 1 | 1); 43 } 44 /*void pushdown(int now) 45 { 46 if(lazy[now]) 47 { 48 Max[now] += lazy[now]; 49 lazy[now << 1] += lazy[now]; 50 lazy[now << 1 | 1] += lazy[now]; 51 lazy[now] = 0; 52 } 53 }*/ 54 void pushdown(int now) 55 { 56 if(lazy[now]) 57 { 58 lazy[now << 1] += lazy[now]; 59 lazy[now << 1 | 1] += lazy[now]; 60 Max[now << 1] += lazy[now]; 61 Max[now << 1 | 1] += lazy[now]; 62 lazy[now] = 0; 63 } 64 } 65 void update(int L, int R, int now) 66 { 67 // pushdown(now); 68 if(L == l[now] && R == r[now]) 69 { 70 Max[now]++; 71 lazy[now]++; 72 return; 73 } 74 pushdown(now); 75 int mid = (l[now] + r[now]) >> 1; 76 if(R <= mid) update(L, R, now << 1); 77 else if(L > mid) update(L, R, now << 1 | 1); 78 else {update(L, mid, now << 1); update(mid + 1, R, now << 1 | 1);} 79 if(l[now] == r[now]) printf("HAHA\n"); 80 Max[now] = max(Max[now << 1], Max[now << 1 | 1]); 81 } 82 /*ll query(int L, int R, int now) 83 { 84 // pushdown(now); 85 if(L == l[now] && R == r[now]) return Max[now]; 86 pushdown(now); 87 int mid = (l[now] + r[now]) >> 1; 88 if(R <= mid) return query(L, R, now << 1); 89 else if(L > mid) return query(L, R, now << 1 | 1); 90 else return max(query(L, mid, now << 1), query(mid + 1, R, now << 1 | 1)); 91 }*/ 92 93 int main() 94 { 95 freopen("aotusi.in", "r", stdin); 96 freopen("aotusi.out", "w", stdout); 97 n = read(); m = read(); 98 mp.clear(); 99 for(int i = 1; i <= m; ++i) 100 { 101 a[i].x = read(); a[i].y = read(); 102 // ll tpa = a[i].x, tpb = a[i].y; 103 t[++pos] = a[i].x; t[++pos] = a[i].y; 104 } 105 sort(t + 1, t + pos + 1); 106 for(int i = 1; i <= pos; ++i) 107 { 108 int tpa = mp[t[i]]; 109 if(!tpa) mp[t[i]] = ++cnt; 110 } //if(!mp[t[i]]) mp[t[i]] = ++cnt; 111 printf("%d\n", cnt); 112 build(1, cnt, 1); 113 for(int i = 1; i <= m; ++i) 114 { 115 int tpa = mp[a[i].x], tpb = mp[a[i].y]; 116 // printf("%d %d\n", tpa, tpb); 117 if(tpa > tpb) swap(tpa, tpb); 118 update(tpa, tpb, 1); 119 } 120 // printf("%lld\n", query(1, cnt, 1)); 121 printf("%d\n", Max[1]); 122 return 0; 123 }
标签:ret uil swap pen stdout += for int UI
原文地址:https://www.cnblogs.com/mrclr/p/9136497.html