HUSTzyk

763

UNIT
acwing_6153

zhs12345
Aro
-瑾年
Jayjingle
ZMXJ

Yuki13

keatsli
195856
wqzgg

Nobody_Z

HUSTzyk
1个月前

#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_set>

using namespace std;

int n;
string str;
unordered_set<string> S;

bool check(int mid)
{
S.clear();
for (int i = 0; i + mid - 1 < n; i ++ )
{
string s = str.substr(i, mid);
if (S.count(s)) return false;
S.insert(s);
}

return true;
}

int main()
{
cin >> n >> str;

int l = 1, r = n;
while (l < r)
{
int mid = l + r >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}

cout << r << endl;

return 0;
}


HUSTzyk
1个月前

#include <iostream>

using namespace std;

typedef long long LL;

const int N = 100010;

LL n, p = 0, q = 0;
LL a[N];

int main()
{
cin >> n;
for(int i = 1; i <= n; i ++ ) cin >> a[i];
for(int i = 2; i <= n; i ++ )
{
int c = a[i] - a[i - 1];
if(c > 0) p += c;
else q += -c;
}
cout << max(p, q) << endl << abs(p - 1) + 1 << endl;

return 0;
}


HUSTzyk
1个月前

HUSTzyk
1个月前

#include<iostream>
#include<cstdio>

using namespace std;

const int N = 1e3 + 10;

int n, m, q;
int a[N][N], b[N][N];

void insert(int x1, int y1, int x2, int y2, int c)
{
b[x1][y1] += c;
b[x2 + 1][y1] -= c;
b[x1][y2 + 1] -= c;
b[x2 + 1][y2 + 1] += c;
}

int main(void)
{
// cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m >> q;
for(int i = 1; i <= n; i ++ )
for(int j = 1; j <= m; j ++ )
cin >> a[i][j];

//构建差分数组
for(int i = 1; i <= n; i ++ )
{
for(int j = 1; j <= m; j ++ )
{
insert(i, j, i, j, a[i][j]);
}
}

while(q -- )
{
int x1, y1, x2, y2, c;
cin >> x1 >> y1 >> x2 >> y2 >> c;
insert(x1, y1, x2, y2, c);
}

//二维前缀和
for(int i = 1; i <= n; i ++ )
{
for(int j = 1; j <= m; j ++)
{
b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
}
}

for(int i = 1; i <= n; i ++ )
{
for(int j = 1; j <= m; j ++ )
{
printf("%d ", b[i][j]);
}
printf("\n");
}

return 0;
}


HUSTzyk
1个月前

#include<iostream>

using namespace std;

const int N = 100010;

int n, m;
int a[N], b[N];

int main(void)
{
cin >> n >> m;
for(int i = 1; i <= n; i ++ )
{
cin >> a[i];
b[i] = a[i] - a[i - 1];
}

int l, r, c;
while(m -- )
{
cin >> l >> r >> c;
b[l] += c;
b[r + 1] -= c;
}

for(int i = 1; i <= n; i ++ )
{
a[i] = b[i] + a[i - 1];
cout << a[i] << ' ';
}

return 0;
}


HUSTzyk
1个月前
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 2 * 10e5 + 10;

int n, a[N];

int main()
{
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];

int l = N;
for(int i = n; i >= 1; i--)
{
l = min(l, i - a[i] + 1);
if(l <= i) a[i] = 1;
}

for(int i = 1; i <= n; i++) cout << a[i] << " ";
cout << endl;
}
return 0;
}


HUSTzyk
1个月前

#include<iostream>

using namespace std;

const int N = 1010;

int n, m, q;
int a[N][N], s[N][N];

int main()
{
scanf("%d%d%d", &n, &m, &q);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scanf("%d", &a[i][j]);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];

while( q -- )
{
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
printf("%d\n", s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1]);
}

return 0;
}


HUSTzyk
1个月前
#include<iostream>

using namespace std;

const int N = 1e6 + 10;

int n, m;
int s[N];

int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++ )
{
int x;
cin >> x;
s[i] = s[i - 1] + x;
}

while(m -- )
{
int l, r;
cin >> l >> r;
cout << s[r] - s[l - 1] << endl;
}

return 0;
}


HUSTzyk
1个月前

#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 100010;

int n, s[N];

int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; i ++ )
{
int x;
scanf("%d", &x);
s[i] = s[i - 1] + x;
}

if(s[n] % 3) puts("0");
else
{
LL res = 0, cnt = 0;
for(int j = 2; j < n; j ++ )
{
if(s[j - 1] == s[n] / 3) cnt ++ ;
if(s[j] == s[n] / 3 * 2) res += cnt;
}

printf("%lld\n", res);
}

return 0;
}


HUSTzyk
2个月前

#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

const int N = 100010;

int n;
struct Range
{
int l, r;
bool operator< (const Range &W)
{
return l < W.l;
}
} ranges[N];

int main()
{
cin >> n;

for(int i = 0; i < n; i ++ )
{
int l, r;
cin >> l >> r;
ranges[i] = {l, r};
}

sort(ranges, ranges + n);

priority_queue<int, vector<int>, greater<int>> heap;
for(int i = 0; i < n; i ++ )
{
auto r = ranges[i];
if(heap.empty() || heap.top() >= r.l) heap.push(r.r);
else
{
int t = heap.top();
heap.pop();
heap.push(r.r);
}
}

printf("%d\n", heap.size());

return 0;
}