forked from datourat/Gorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.h
154 lines (120 loc) · 2.36 KB
/
Util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef UTIL_H_
#define UTIL_H_
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
namespace Gorder
{
using namespace std;
unsigned long long MyRand64();
string extractFilename(const char* filename);
void quit();
template<class T>
void VectorPreprocessing(vector<T>& v, T u){
if(v.size()<2)
return ;
int p1, p2;
sort(v.begin(), v.end());
p1=0;
p2=1;
while(v[0]==u){
v.erase(v.begin());
}
while(p2<v.size()){
if(v[p2]==u || v[p1]==v[p2]){
v.erase(v.begin()+p2);
continue;
}
p1++;
p2++;
}
}
inline int IntersectionSize(const int* v1, const int* v2, int s1, int s2, int u){
int i=upper_bound(v1, v1+s1, u)-v1;
int j=lower_bound(v2, v2+s2, v1[i])-v2;
int count=0;
while(i<s1&&j<s2){
if(v1[i]<v2[j]){
i++;
} else if(v1[i]>v2[j]){
j++;
} else {
count++;
i++;
j++;
}
}
return count;
}
template<class T>
bool VectorEq(const vector<T>& v1, const vector<T>& v2){
if(v1.size()!=v2.size())
return false;
for(int i=0; i<v1.size(); i++){
if(v1[i]!=v2[i])
return false;
}
return true;
}
template<class T>
bool IsIntersect(const vector<T>& v1, const vector<T>& v2){
int i=0, j=0;
while(i<v1.size()&&j<v2.size()){
if(v1[i]==v2[j]){
return true;
}
if(v1[i]<v2[j]){
i++;
}
if(v1[i]>v2[j]){
j++;
}
}
return false;
}
template<class T1, class T2>
class PairCompare{
bool flag;
public:
PairCompare(bool in){
flag=in;
}
bool operator()(const pair<T1, T2>& p1, const pair<T1, T2>& p2){
if(flag)
return p1.second < p2.second;
else
return p1.second > p2.second;
}
};
template<class T1, class T2>
class PairComparePointer{
public:
bool operator()(const pair<T1, T2>& p1, const pair<T1, T2>& p2){
return *(p1.second) > *(p2.second);
}
};
template<class T>
inline T MyMin(const T& left, const T& right){
if(left<right)
return left;
else
return right;
}
template<class T1, class T2>
class ReRank{
const vector<T2>& value;
public:
ReRank(vector<T2>& v): value(v){
}
bool operator()(const T1& left, const T1& right){
return value[left] < value[right];
}
};
}
#endif