I solved the problem with three pointers. But when I sort the vectors first and the resize, I get an AC. If I sort them after making them unique, I get a WA.
AC Code
WA Code
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Doubt Regarging std::unique() | AC vs WA
I solved the problem with three pointers. But when I sort the vectors first and the resize, I get an AC. If I sort them after making them unique, I get a WA.
long triplets(vector<int> a, vector<int> b, vector<int> c) {
sort(all(a));
sort(all(b));
sort(all(c));
a.erase(unique(all(a)), a.end());
b.erase(unique(all(b)), b.end());
c.erase(unique(all(c)), c.end());
int n = a.size(), m = b.size(), l = c.size();
int i = 0, j = 0, k = 0;
long ans = 0;
for(int j = 0; j < m; j++) {
while(i < n and a[i] <= b[j]) i++;
while(k < l and c[k] <= b[j]) k++;
ans += 1LL*i*k;
}
return ans;
}
long triplets(vector<int> a, vector<int> b, vector<int> c) {
a.erase(unique(all(a)), a.end());
b.erase(unique(all(b)), b.end());
c.erase(unique(all(c)), c.end());
sort(all(a));
sort(all(b));
sort(all(c));
int n = a.size(), m = b.size(), l = c.size();
int i = 0, j = 0, k = 0;
long ans = 0;
for(int j = 0; j < m; j++) {
while(i < n and a[i] <= b[j]) i++;
while(k < l and c[k] <= b[j]) k++;
ans += 1LL*i*k;
}
return ans;
}
Название |
---|