Compare commits

...

2 Commits

Author SHA1 Message Date
797976b853 update 2025-08-25 17:25:22 +08:00
a8ea175f77 update 2025-08-25 14:34:28 +08:00
2 changed files with 95 additions and 35 deletions

59
src/8/24/P1020.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>
using ll = int64_t;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::vector<ll> v;
v.reserve(100000);
ll tmp;
while (std::cin >> tmp) {
v.push_back(tmp);
}
if (v.empty()) {
std::cout << "0\n0\n";
return 0;
}
std::vector<ll> f(v.size() + 1, 0);
f[1] = v[0];
ll maxdp = 1;
for (ll i = 1; i < v.size(); i++) {
ll h = v[i];
ll l = 1, r = maxdp, ans = 0;
while (l <= r) {
ll mid = (l + r) >> 1;
if (f[mid] >= h) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
if (ans == 0) {
f[1] = std::max(f[1], h);
} else {
ll nxt = ans + 1;
if (nxt > maxdp) {
maxdp = nxt;
f[nxt] = h;
} else {
f[nxt] = std::max(f[nxt], h);
}
}
}
std::cout << maxdp << '\n';
std::vector<ll> sys;
sys.reserve(v.size());
for (ll h : v) {
auto it = std::lower_bound(sys.begin(), sys.end(), h);
if (it == sys.end()) sys.push_back(h);
else *it = h;
}
std::cout << sys.size() << '\n';
return 0;
}

View File

@ -1,40 +1,41 @@
#include <vector>
#include <iostream>
using namespace std;
class Solution {
public:
vector<int> findDiagonalOrder(const vector<vector<int>>& m) {
int x=0,y=0;
bool isup=true;
vector<int> res;
res.reserve(m.size());
#define isout (x<0||x>m.size()||y<0||y>m[0].size())
do{
res.push_back(m[x][y]);
if(isup){
if(x==0){
++y;
isup=false;
}else{
--x;
++y;
}
}else{
if(y==0){
++x;
isup=true;
}else{
++x;
--y;
}
}
}while(!(x==m.size()&&y==m[0].size()));
return res;
const int N = 1000;
int c[N];
int logic(int x, int y) {
return (x & y) ^ ((x ^ y) | (~x & y));
}
void generate(int a, int b, int *c) {
for (int i = 0; i < b; i++)
c[i] = logic(a, i) % (b + 1);
}
void recursion(int depth, int *arr, int size) {
if (depth <= 0 || size <= 1) return;
int pivot = arr[0];
int i = 0, j = size - 1;
while (i <= j) {
while (arr[i] < pivot) i++;
while (arr[j] > pivot) j--;
if (i <= j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++; j--;
}
}
};
recursion(depth - 1, arr, j + 1);
recursion(depth - 1, arr + i, size - i);
}
int main(){
Solution s;
s.findDiagonalOrder({{1,2,3},{4,5,6},{7,8,9}});
int main() {
int a, b, d;
cin >> a >> b >> d;
generate(a, b, c);
recursion(d, c, b);
for (int i = 0; i < b; ++i) cout << c[i] << " ";
cout << endl;
}